4

I am working on a 3 branch project.

I am on branch1, and there is master branch.

When I need to pull and merge something from master:

git checkout master
git pull origin master
git checkout branch1
git merge master

is there a way to pull the master changes from my branch so I don't have the needed to do merge ?

something like:

git pull origin master

but from branch1 without switching to master branch.

EDIT

Resume:

I have 3 branches: every time there is something new in master, I don't want to switch to branch master. All I want is to pull the master new features into my branch, without going to the master branch.

Non
  • 8,409
  • 20
  • 71
  • 123
  • It's a bit unclear what you mean by *pull*. Pulling and *merging* are two different concepts. – Willem Van Onsem May 19 '15 at 23:32
  • 2
    I think you need to switch to a branch to pull, in case there are conflicts - you cannot resolve the conflicts without checking out...but never say never with git. – Andy Joiner May 19 '15 at 23:32
  • @CommuSoft if I pull the changes to my branch from master, then I don't need to do merge right ? – Non May 19 '15 at 23:33
  • You can either do a *merge* or a *rebase*... – Willem Van Onsem May 19 '15 at 23:35
  • @CommuSoft can you put answer for it ? – Non May 19 '15 at 23:35
  • 1
    Well it's a bit unclear whether you mean *from* your master or *to* your master. Do you want to update the master, or your branch... – Willem Van Onsem May 19 '15 at 23:36
  • @CommuSoft I want update my branch, pulling the changes from master without switching to master. – Non May 19 '15 at 23:37
  • You need to understand the difference between master and origin/master...and yes, you should be able to do what you want. – Andy Joiner May 19 '15 at 23:41
  • Why are you guys complicating everything ? I have 3 branches: every time there is something new in master, I don't want to switch to branch master. All I want is pull the master new features into my branch, without going to the master branch. That is it. – Non May 19 '15 at 23:44
  • I think rebase is the command you are looking for. This will apply all changes of a branch onto the branch you are currently on. – Tim van der Lippe May 19 '15 at 23:53
  • Just setup your branch to track master? `git branch --set-upstream-to origin/master` – Andrew C May 20 '15 at 00:52

2 Answers2

6

You may want to use rebase, so that you can merge your master changes onto your branch you are working

git fetch origin            # Updates origin/master
git rebase origin/master    # Rebases current branch onto origin/master

Also check out this question

Update: Recent Git versions provide a simpler way to do the equivalent of the above two commands.

git pull --rebase origin master
# where --rebase[=(false|true|merges|preserve|interactive)]
ThanosFisherman
  • 5,626
  • 12
  • 38
  • 63
1

From your working folder with branch1 checked out:

git fetch
git merge origin/master

The fetch downloads changes from the remote repo to your machine, but does not apply them to your working folder. The merge applies what you just downloaded to your working folder (whichever branch you are currently on)

Andy Joiner
  • 5,932
  • 3
  • 45
  • 72