Marvin3
Marvin3

Reputation: 6041

Git: pull from remote but keep local commits

For example: there is a local and remote repo with two files:

1.txt
2.txt

Developer #1 edits 1.txt locally and commits the changes without pushing them to remote repo.

Later, developer #2 sends pull request with edited 2.txt, and it gets merged in main remote repo.

My question is: how can developer #1 pull 2.txt from remote repo, and keep changes to 1.txt?

When I try to do this, extra commit is added after 1.txt edit, so it looks like this:

Thank you.

Upvotes: 3

Views: 3535

Answers (1)

Lajos Veres
Lajos Veres

Reputation: 13725

You should use

git pull --rebase

Your commit would be replayed after the other one this way, so its sha hash will change, but otherwise it will be the same. And this way you can avoid the extra "merge commit".

Upvotes: 7

Related Questions