2

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?

hitchhiker
  • 1,099
  • 5
  • 19
  • 44
  • Possible duplicate of [Can "git pull --all" update all my local branches?](https://stackoverflow.com/questions/4318161/can-git-pull-all-update-all-my-local-branches) – tymtam Oct 23 '19 at 06:26

3 Answers3

2

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.)

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
1

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

-- Yes. There is a possibility to use the --all option with the git pull command, but then that only updates the information about all branches. It wouldn't pull the code on all branches.

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

-- No. To pull the code into a specific branch, you would need to checkout the branch explicitly and then use the git pull command.

Dev
  • 21
  • 3
  • 1
    I think you're confused about `--all`. It's passed through to `git fetch` for the case when you have multiple remotes (e.g. the upstream copy as well as your fork of it). – o11c Oct 22 '19 at 22:11
  • Yes, that's right ! I was confused at the outset since I thought a **git pull --all** would update all feature branches when this command is used from the *master* branch. – Dev Oct 22 '19 at 22:34
1

Pure git

Git's documentation is very clear on this.

Incorporates changes from a remote repository into the current branch. In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.

More precisely, git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch. With --rebase, it runs git rebase instead of git merge.

You can fetch all remotes with --all.

--all

Fetch all remotes.

Note it's 'Fetch', not 'Pull', 'merge' or 'integrate'.


hub's hub-sync

You could try using GitHub's hub. Its hub-sync command syncs local branches.

Fetch git objects from upstream and update local branches. Synopsis

hub sync [--color]

  • If the local branch is outdated, fast-forward it;
  • If the local branch contains unpushed work, warn about it;
  • If the branch seems merged and its upstream branch was deleted, delete it.

If a local branch does not have any upstream configuration, but has a same-named branch on the remote, treat that as its upstream branch.

tymtam
  • 31,798
  • 8
  • 86
  • 126