git - Batch file : git checkout branch using variables
问题描述
I have an issue to set up this batch. I want to get to my project directories, git fetch -all, switch branch to develop, pull, and go back to my actual branch For now I have succeded in doing so, but is's impossible to checkout a branch using variables I don't know why..
In short what I want to achieve is (on branch develop):
set current_branch=custom
git checkout %current_branch%
Here is the complete batch file
@echo off
SET project_array="c:\example\project01" "c:\example\project02"
for %%a in (%project_array%) do (
echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo fetching datas for project at: %%a
cd %%a
@echo on
for /F "tokens=*" %%i in ('git branch --show-current') do set current_branch=%%i
git fetch --all
git checkout develop
git pull
git checkout %current_branch%
@echo off
)
PAUSE
解决方案
try this (not tested):
@echo off
SET "project_array="c:\example\project01" "c:\example\project02""
setlocal enableDelayedExpansion
for %%a in (%project_array%) do (
echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo fetching datas for project at: %%a
cd %%a
@echo on
for /F "tokens=*" %%i in ('git branch --show-current') do set current_branch=%%i
git fetch --all
git checkout develop
git pull
git checkout !current_branch!
@echo off
)
PAUSE
More on Delayed Expansion
推荐阅读
- python - matplotlib.pyplot 文档说它是 matplotlib 的基于状态的接口。什么是基于状态的接口?
- c# - 错误 500:SRVE0295E:报告错误:500 - HttpWebResponse
- load-balancing - 如何将一个 HAProxy 服务器用于多个域
- amazon-web-services - 将数据从 Object Storage 存储桶(scaleway)复制到 aws s3 存储桶
- r - 使用 auto.Arima() 和 xreg 问题进行 ARIMA 预测
- scala - Scala检查对象是否是选项
- sql-server - 如何从 CATCH it T-SQL 中触发 SQL 异常?
- html - CSS 过渡字体真棒内容
- javascript - Angular,量角器自动测试定位器不起作用
- asp.net - Visual Studio asp.net 完整框架项目中的 Bootstrap 4