If I'm working locally,and I need to get the latest code on remote master branch, one way is to switch to local master and do git pull . However, this fetches only the changes after the HEAD of local master. If the remote master is changed in such a way that, underlying commits before local HEAD are also modified, how can I get them, without needing to do a whole git clone again?
-
1possible duplicate of [Force Git to overwrite local files on pull](http://stackoverflow.com/questions/1125968/force-git-to-overwrite-local-files-on-pull) – Andrey Deineko Jan 20 '15 at 06:36
2 Answers
git pull -f
Should do what you seek if I recall, it overrides checks which ensure you are pulling only a descendant and forces clobbering of the local differences.

- 6,577
- 3
- 27
- 48
I guess someone has added a change to the remote master when you were working with your code and you want a simple way to add those changes to your (master) branch. Please use
git pull --rebase
or to target specific branch
git pull --rebase <origin> <target branch>
for example
git pull --rebase origin master
Why rebase? If you want to keep commit history clean, then use rebase. Rebase keeps your and remote commit histories clean. Merge sums up changes and looses commit history. You can look up short explanation about differences.
In an ideal world you and other(s) edited files or sections do not overlap. After rebase there should be no conflicts. But we don't live in a perfect world.
If there are conflicts you have to resolve them.
From command line you can use
git mergetool
to resolve conficts. Setting up a mergetool is another question. After conflicts are resolved remember to tell it to git repository. Type
git rebase –continue
Now you should be good to go and continue coding or you can commit your changes to the remote branch.