1

I know I can test this experimentally, but having discussion would be nice. If I have a local head on (local branch) master that has diverged from the remote master, I tend to do a git pull --rebase to replay my changes. I believe this works by changing the state of my local branch a little bit.

However, if I have branched from one of the local commits into a new branch experimental (which does not exist on remote), then will the history/commits of experimental be updated by the rebase on the local master branch?

A similar question is when I have two local branches of master and dev, both tracking remotes. There are local commits in both, and I've merged some of the local commits from master into dev. Now I rebase master to be applied on top of the remote -- does this change the commits that I have merged into my local dev branch? Will my local dev branch now include the (previously remote-only) commit history that I now see in my master branch?

Hamy
  • 20,662
  • 15
  • 74
  • 102

1 Answers1

1

Will the history/commits of experimental be updated by the rebase on the local master branch?

The answer is no. Performing a normal git pull on master is the same as performing these two commands... (assuming origin is the remote, and your on the master branch)

git fetch
git merge origin/master

When you add the --rebase flag, it changes the pull to perform these two commands instead...

git fetch
git rebase origin/master

As you can see, the rebase performed is a simple rebase with no additional references. This is a shorthand, git assumes the current branch as a second parameter. When a rebase is performed this way while on master, it is assumed to mean this...

git rebase origin/master master

The above could be performed from any branch or even a headless state, and it would still result in the same thing as simple using git rebase origin/master, because that second parameter is target reference. To quote the documentation...

git rebase master 
git rebase master topic

NOTE: The latter form is just a short-hand of git checkout topic followed by git rebase master. When rebase exits topic will remain the checked-out branch.

Obviously since the current branch is assumed to be the target of the rebase, there is no chance of this effecting other branches.

As a general rule, git wont do anything to all your branches.

Your second question

Unfortunatly, I'm having trouble following your scenario. I ask that you either break it up into smaller questions, simplify it to the core of what your trying to understand. Additionally, you might want to create a simple text diagram of the commit history in your scenario similar to what was done on this question.

I think this is the crucial part that needs clarification...

"Now I rebase master to be applied on top of the remote..."

We need to understand what you mean by "on top of". Try showing us the series of git commands, in particular this final rebase.

That said, my the answer to the following...

"Will my local dev branch now include the (previously remote-only) commit history that I now see in my master branch?"

... is likely to be yes. After rebasing from anywhere into master, you will then see the commits on master that used to be only on the place you rebased from.

Community
  • 1
  • 1
eddiemoya
  • 6,713
  • 1
  • 24
  • 34