So, you made local changes in your local repository. Then, to get remote changes to the local repository without making changes to the local files, you can use git fetch . In fact, git pull is a two-step operation: non-destructive git fetch followed by git merge . See What is the difference between 'git pull' and 'git fetch'? for further discussion.
Detailed example:
Suppose your repository is similar to this (you made changes to test2 :
* ed0bcb2 - (HEAD, master) test2 * 4942854 - (origin/master, origin/HEAD) first
And the origin repository is similar to this (someone else did test1 ):
* 5437ca5 - (HEAD, master) test1 * 4942854 - first
At this point, git will complain and ask you to pull first if you try to push your test2 to a remote repository. If you want to see test1 not modifying your local repository, run this:
$ git fetch
The local result repository will look like this:
* ed0bcb2 - (HEAD, master) test2 | * 5437ca5 - (origin/master, origin/HEAD) test1 |/ * 4942854 - first
Now you have the remote changes in another branch, and you keep your local files intact.
Then what's next? Usually you want to combine your changes with deleted changes, and then commit and click. But if you do not want to use your changes exclusively (if this means that you are overwriting the remote repo), you need to create a new branch (except master ) for your test2 and push this branch to the remote repository.
xiaobai 07 Oct '13 at 3:44 2013-10-07 03:44
source share