Merge, update, and pull Git branches without using checkouts

前端 未结 17 1819
臣服心动
臣服心动 2020-11-22 07:42

I work on a project that has 2 branches, A and B. I typically work on branch A, and merge stuff from branch B. For the merging, I would typically do:

git mer         


        
17条回答
  •  无人共我
    2020-11-22 08:18

    Another way to effectively do this is:

    git fetch
    git branch -d branchB
    git branch -t branchB origin/branchB
    

    Because it's a lower case -d, it will only delete it if the data will still exist somewhere. It's similar to @kkoehne's answer except it doesn't force. Because of the -t it will set up the remote again.

    I had a slightly different need than OP, which was to create a new feature branch off develop (or master), after merging a pull request. That can be accomplished in a one-liner without force, but it doesn't update the local develop branch. It's just a matter of checking out a new branch and having it be based off origin/develop:

    git checkout -b new-feature origin/develop
    

提交回复
热议问题