Git merge master into feature branch

后端 未结 11 701
既然无缘
既然无缘 2020-11-27 08:56

Let’s say we have the following situation in Git:

  1. A created repository:

    mkdir GitTest2
    cd GitTest2
    git init
    
  2. Some m

11条回答
  •  萌比男神i
    2020-11-27 09:15

    Here is a script you can use to merge your master branch into your current branch.

    The script does the following:

    • Switches to the master branch
    • Pulls the master branch
    • Switches back to your current branch
    • Merges the master branch into your current branch

    Save this code as a batch file (.bat) and place the script anywhere in your repository. Then click on it to run it and you are set.

    :: This batch file pulls current master and merges into current branch
    
    @echo off
    
    :: Option to use the batch file outside the repo and pass the repo path as an arg
    set repoPath=%1
    cd %repoPath%
    
    FOR /F "tokens=*" %%g IN ('git rev-parse --abbrev-ref HEAD') do (SET currentBranch=%%g)
    
    echo current branch is %currentBranch%
    echo switching to master
    git checkout master
    echo.
    echo pulling origin master
    git pull origin master
    echo.
    echo switching back to %currentBranch%
    git checkout %currentBranch%
    echo.
    echo attemting merge master into %currentBranch%
    git merge master
    echo.
    echo script finished successfully
    PAUSE
    

提交回复
热议问题