Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confused about git rebase

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
like image 488
Ankur Agarwal Avatar asked Jun 03 '26 11:06

Ankur Agarwal


1 Answers

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

like image 65
Bacon Avatar answered Jun 06 '26 03:06

Bacon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!