How to extract files from a remote computer without overwriting local files?

I am trying to create a new git repo for a pre-existing remote repo.

I want my local files to overwrite the remote repo, but git says I first need to extract these deleted files and merge them.

Is there a way to pull, but make sure the local files are not overwritten by the remote?

+55
git github
Oct 07 '13 at 2:53 on
source share
3 answers

Well yes and no ...

I understand that you want your local copies to "redefine" what is on the remote control, but oh man, if someone changed the files in the remote repo in several ways, and you just ignore their changes and try to "force "your own changes, without even looking at possible conflicts, well, I’m paying for you (and your colleagues); -)

However, it is really easy to do the "right thing ..."

Step 1:

git stash 

at your local repo. This will save your local updates in the wallet, and then return the changed files back to the state of preliminary editing.

Step 2:

 git pull 

to get any modified versions. Now, I hope you don’t have new versions of the files you are worried about. If it is not, then the next step will work smoothly. If so, then you have a job and you will be glad you did.

Step 3:

 git stash pop 

This will combine your modified versions that you hid in step 1 with the versions you just pulled out in step 2. If everything goes smoothly, then you will install everything!

If, on the other hand, there were real conflicts between what you did in step 2 and your changes (because someone else was editing the interim period), you will find out and ask them to resolve. Do it.

Everything will work much better - it will probably save your changes without any real work on your part, warning you of serious serious problems.

+82
Oct 07 '13 at 3:06 on
source share

First you can hide your local changes first, then pull, then pop up.

 git stash git pull origin master git stash pop 

Anything that overrides changes from the remote will have conflicts that you will have to resolve manually.

+9
Oct 07 '13 at 2:59
source share

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.

+3
07 Oct '13 at 3:44
source share



All Articles