Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: pull from remote but keep local commits

Tags:

git

github

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:

  • 14:00 2.txt commit from developer #2
  • 15:00 1.txt commit from developer #1
  • 16:00 Merge branch "master" of https://github... (2.txt commit again)

Thank you.

like image 456
Marvin3 Avatar asked Nov 22 '25 00:11

Marvin3


1 Answers

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".

like image 146
Lajos Veres Avatar answered Nov 23 '25 14:11

Lajos Veres



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!