Reputation:
I am new to Git and trying to figure this out.
I have cloned a remote repository, say ssh://repo to my local machine. After cloning, I edited some files, during which time the remote repository was also changed.
How can I update my local repository with the remote one, while maintaining both sets of changes?
Upvotes: 4
Views: 13554
Reputation: 603
"git pull" will merge remote the remote changes into your local copy. If you want to maintain your changes independently, you can move the changes to a new branch before you pull. So if you haven't yet committed your changes, you could do something like this:
> git stash #stash the changes
> git branch dev_branch #create a new branch
> git checkout dev_branch #move to the new branch
> git stash apply #paste the changes into the new branch
> git checkout master #switch back to the master branch
> git pull #update the master branch
At the end of that you have one version of the code contains your changes (dev_branch) and one that matches the remote code (master). You can now work on your dev_branch independent of whatever happens to the remote code. (When you get to know git you;ll find this is a more "git" way of working - just working in your master branch and doing "git pull" to merge in remote changes is a more of a "subversion" way of working).
Upvotes: 2
Reputation: 1581
Just commit your changes to your local repository using
git commit
command. Now you never lose your changes! Then pull new changes from remote repository using
git pull
command. This command fetches a new changes and merge them with your changes. Usually there is no conflicts. In this case you free to push your changes to remote repository. Otherwise you need to resolve all conflicts, mark them resolved using
git add
command (just use hints from git status output) and commit this merge using
git commit
command.
Upvotes: 3
Reputation: 3315
you can use command 'git pull' and this flag merge conflicts if any. If there are conflicts, resolve it and should do git commit
Upvotes: 0