0
$ git --version
git version 1.7.1
$ git branch -avv
* master                017Fcc0 [origin/master] xxxx
  remotes/origin/HEAD   -> origin/master

My understand is that the origin/master is the remote master branch path name and master is my local branch name. I need to combine multiple my local commits into one and then submit it to remote server with latest time stamp. The following three steps serve me well but I don't understand why I need to use origin/master instead of master.

   a) git rebase --ignore-date origin/master
   b) git rebase -i origin/master
   c) git push origin master:master
q0987
  • 34,938
  • 69
  • 242
  • 387
  • Possible duplicate of ["git rebase origin" vs."git rebase origin/master"](https://stackoverflow.com/questions/5963597/git-rebase-origin-vs-git-rebase-origin-master) – phd Aug 31 '17 at 21:52

1 Answers1

3

You don't need to use origin/master in order to combine multiple commits into one. But it is a good way to do it in order to avoid having to overwrite history on the origin.

For instance, if you history looks like:

5abcde Commit 5 [master] [HEAD]
4abcde Commit 4
3abcde Commit 3
2abcde Commit 2 [origin/master]
1abcde Commit 1

And your master points to 5abcde and origin/master points to 3abcde. If you run git rebase master you rebase your current position (which is probably already master) on the same position, effectively doing nothing.

Running git rebase origin/master or git rebase 2abcde would apply the commits that you have (3,4,5) after the commit (2) - and if you specify the flag -i gives you the option to squash/fixup/skip/reword/drop/pick the commits 3,4,5 respectively.

The Git documentation is imho actually very good on explaining on how rebase works: https://git-scm.com/docs/git-rebase

Perhaps it helps to read up a bit more on how Git works with regards to remotes: https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes

gernberg
  • 2,587
  • 17
  • 21