Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git pull: replace local version with the remote version

Tags:

git

There is something I don't understand with the git pull command. I have a foobar Git repository with two files, named f1 and f2. First, I clone this repo using this command:

git clone git@mycompany:foobar/foobar.git  

I make some wrong modifications to both the f1 and f2 files, add them to Git index and commit then.

git add -A git commit -m 'a test wrong modification' 

I decide now that this modifications were wrong and I want to replace my files with the remote version. So I use git pull to do this.

git pull 
Already up-to-date. 

Git answers that project is already up to date. What's wrong with what I'm doing? How should I proceed to replace my local version with the remote version?

like image 565
ben.IT Avatar asked Jun 27 '13 07:06

ben.IT


People also ask

Does git pull overwrite local?

The reason for error messages like these is rather simple: you have local changes that would be overwritten by the incoming new changes that a "git pull" would bring in. For obvious safety reasons, Git will never simply overwrite your changes.

How do I overwrite local master with remote?

If you need to completely replace the history of your local master with your remote master (for example, if you've been playing with commits or rebase), you can do so by renaming your local master, and then creating a new master branch.


1 Answers

git fetch origin git reset --hard origin/master 

Here is the good explanation about git pull git pull

The git fetch command imports commits from a remote repository into your local repo. The resulting commits are stored as remote branches instead of the normal local branches that we’ve been working with. This gives you a chance to review changes before integrating them into your copy of the project.

Command git pull <remote> fetches the specified remote’s copy of the current branch and immediately merge it into the local copy. This is the same as git fetch <remote> followed by git merge origin/<current-branch>. Since it is doing merge your commits were still there.

After doing fetch you can reset your working copy with reset command. Hard is to ignore any changes in your local copy. git reset --hard origin/master

like image 154
Tala Avatar answered Oct 04 '22 15:10

Tala