0

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?

user3274539
  • 687
  • 2
  • 8
  • 18

1 Answers1

2

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • So if I understand correctly, I have checkouted on remote branch tmp, did some changes, now if I do git fetch i will not be able to push my changes? I have to do git pull --rebase and then I can push? – user3274539 May 22 '14 at 10:47
  • `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. – VonC May 22 '14 at 10:54