3

My workflow:

$ git remote -v
origin  [email protected]:abc/dev.git (fetch)
origin  [email protected]:abc/dev.git (push)
upstream  [email protected]:companyname/dev.git (fetch)
upstream  [email protected]:companyname/dev.git (push)

Fork [email protected]:companyname/dev.git using github web interface. Create [email protected]:abc/dev.git

Now:

1. git clone [email protected]:abc/dev.git
2. git remote add origin [email protected]:abc/dev.git
3. git remote add upstream [email protected]:companyname/dev.git 
4. git checkout -b upstream-master upstream/master
5. git checkout -b master origin/master

Now modify some code and create a commit on local master branch.

5.1. git add somecode.c
5.2. git commit -m "my commit for which I will make a PR" 
6. git push origin master

Now go to [email protected]:abc/dev.git on github web interface and create a PR for upstream/master:

Once the PR is merged, do:

7. git checkout upstream-master 
8. git pull --rebase

Now my local upstream-master has PR merge commit but master (which is origin/master) does not.

Q: Which branch should I rebase on which and why ?

After steps 7 and 8 should I do

git rebase origin-master

or should I do

git checkout origin-master 
git rebase upstream-master
Ankur Agarwal
  • 23,692
  • 41
  • 137
  • 208

1 Answers1

1

If you want to retrieve in your local master something that was merged on the remote upstream/master branch, you should:

git checkout master

to position yourself into the local branch that you want to update

and then

git rebase upstream/master

To retrieve the modifications from the remove upstream/master branch into your current, local branch

Bacon
  • 1,814
  • 3
  • 21
  • 36
  • That is the source of my confusion. Why should I not do : `git checkout upstream-master` and `git rebase master` . After all I am trying to `rebase` upstream-master onto master. No ? – Ankur Agarwal Aug 06 '15 at 01:33
  • 2
    Yes, so you need to position yourself into the branch where you want to retrieve the modifications, which is master, in this case. When rebasing, you specify the branch from which you want to get those modifications. – Bacon Aug 06 '15 at 01:36