I have one problem, I have been reading about that but I am not sure which solution is correct and as of now I am unable to test which solution is the right one. So, I am working on a remote branch, changing things, other people are working here too. When I am done I want to push but other people already changed that branch and I can't do that. Whenever I do pull it want to merge the branch. Is there any other way to get latest commits from branch without merging and then push my changes?
- 1Is there any other way to get latest commits from branch without merging and then push my changes? why would you want to do that?Tim– Tim2014-05-22 10:05:11 +00:00Commented May 22, 2014 at 10:05
- I want to get latest changes and then push my ownuser3274539– user32745392014-05-22 10:07:42 +00:00Commented May 22, 2014 at 10:07
1 Answer
If you want to see the most up-to-date upstream branch, you can fetch it (no merge here) and create a temporary branch:
git fetch git checkout -b tmp origin/master That way, you can switch back and forth between tmp and master (your own local branch), and compare their differences (in term of file list).
Note that you won't be able to push your changes without forcing a push and erasing the upstream history.
The best course of action would be to rebase your master branch on top of origin/master:
git pull --rebase (A merge would occur there, but more importantly, your own commits would be replayed on top of the most up-to-date version of the upstream master branch)
Then you would be able to push your own changes.
2 Comments
tmp isn't a remote branch: it is based on one, but it is a local branch. Just a marker to allow you to see what origin/master looks like. As for the rebase, it is mandatory if you want to push your commits: you don't even have to create tmp: you can fetch, and then rebase master or top of origin/master: that is what git pull --rebase does.