Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When will `git pull --rebase` get me in to trouble?

Tags:

git

rebase

pull

I understand that when I use git pull --rebase, git will re-write history and move my local commits to occur after all of the commits in the branch I just pulled from.

What I don't understand is how this would ever be a bad thing. People talk about getting in to trouble with git pull --rebase where you can end up with a branch that other people can't pull from. But I don't get how that's possible since all you're doing is replaying your local, not-yet-public, commits on top of the branch you pulled from. So, what's the problem there?

like image 854
Gabe Hollombe Avatar asked Apr 07 '10 05:04

Gabe Hollombe


People also ask

Is it safe to use git pull -- rebase?

I recommend to use git pull --rebase only if you know you forgot to push your commits before someone else does the same. If you did not commit anything, but your working space is not clean, just git stash before to git pull .

What will git pull -- rebase do?

Git pull rebase is a method of combining your local unpublished changes with the latest published changes on your remote.

When should I not use git rebase?

Since git rebase command essentially re-writes git history, it should never be used on a branch which is shared with another developer (Unless both developers are kind of git experts). Or as its also said, never use the rebasing for public branches.

Do I need to do git pull after rebase?

There is no need to do a git pull after you have rebased your feature branch on top of master .


1 Answers

It is only an issue if you have only published (pushed) some of your commits, because they would be harder to merge to other repos which have already those commits. Since their SHA1 have changed, Git would try to replay them again on those repos.

If you have not (pushed any of those commits again), any rebase should be safe.

So the issue here is: are you sure that all the local commit you are rebasing are still actually... local?
And are you sure of that 'git pull --rebase' after 'git pull --rebase'?

If you are working on a 'private branch' (a branch that you never pushed, but only merge or rebase on a public branch, one that you will push), then you are safe to rebase that private branch any time you want.

In the end, it all depends on the workflow of merge you have chosen to establish.

like image 104
VonC Avatar answered Sep 25 '22 08:09

VonC