How do I execute several git commands in a batch file without terminating after the first command?

后端 未结 3 801
刺人心
刺人心 2020-12-24 04:24

I tried to put a series of GIT commands that I always use continuously togeter as batch files so that I don\'t repeat myself too much. For example, I have this batch file ca

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-24 05:17

    Assuming you are using msysGit as your Git client you might actually want to use Bash scripts for this. You could place a bash function in your ~/.bashrc (~ is usually your C:\Users\- see here) as follows

    update_repo_branch() {
        if [ $# != "2" ]; then
            echo "Usage: update_repo_branch REPO BRANCH" 1>&2
            return 1
        fi
    
        cd $1
        git checkout $2
        git fetch origin
        git merge origin/$2
    }
    

    You can then run update_repo_branch myrepo cool-branch from the mysysGit shell.

    Of course, this won't be accessible from cmd.exe. You will only be able to use it within the msysGit cygwin shell.

提交回复
热议问题