Search code examples
gitgit-pull

Does `git pull` only merge the changes into the branch one is checked out into?


I recently performed the following actions in git:

  1. git checkout a
  2. git pull (this downloaded some new code which was added in another branch b)
  3. git merge master
  4. git checkout master
  5. At this point I expected master to contain the changes downloaded in 2) however they weren't present. I ran git pull again which fetched the changed.

Does git pull fetch and merge the changes only into the current branch (which I'm checked out into)? If yes, is there a git command to merge the downloaded changed into every/specific branches?


Solution

  • Does git pull fetch and merge the changes only into the current branch (which I'm checked out into)?

    Yes.

    If yes, is there a git command to merge the downloaded changed into every/specific branches?

    No, there's not.

    One thing you can do (more or less practical, depending on your specific setting) is to craft a homemade alias for the stable ones, but feature branches would still need to be updated individually when needed.

    An example assuming dev and master branches as stable

    git config --global alias.upd8 '!git stash && git checkout master && git pull && git checkout dev && git pull'
    

    then when you need to update your stable local branches, just

    git upd8
    

    (Since the commands are chained with &&, bash will only proceed if no error code is returned, so it won't go further is for example the current situation is not "stashable" or if one of the merge is problematic.)