How do I get the latest version of my code?

Git

Git Problem Overview


I'm using Git 1.7.4.1.

I want to get the latest version of my code from the repository, but I'm getting errors:

$ git pull
….
M	selenium/ant/build.properties
….
M	selenium/scripts/linux/get_latest_updates.sh
M	selenium/scripts/windows/start-selenium.bat
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as appropriate to mark resolution, or use 'git commit -a'.

I've deleted the local copies of the files the tool is complaining about, but I still get the errors.

How do I check out the latest version from the remote repository?

Git Solutions


Solution 1 - Git

If you don't care about any local changes (including untracked or generated files or subrepositories which just happen to be here) and just want a copy from the repo:

git reset --hard HEAD
git clean -xffd
git pull

Again, this will nuke any changes you've made locally so use carefully. Think about rm -Rf when doing this.

Solution 2 - Git

Case 1: Don’t care about local changes

  • Solution 1: Get the latest code and reset the code

      git fetch origin
      git reset --hard origin/[tag/branch/commit-id usually: master]
    
  • Solution 2: Delete the folder and clone again :D

      rm -rf [project_folder]
      git clone [remote_repo]
    

Case 2: Care about local changes

  • Solution 1: no conflicts with new-online version

      git fetch origin
      git status
    

    will report something like:

      Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
    

    Then get the latest version

      git pull
    
  • Solution 2: conflicts with new-online version

      git fetch origin
      git status
    

    will report something like:

      error: Your local changes to the following files would be overwritten by merge:
          file_name
      Please, commit your changes or stash them before you can merge.
      Aborting
    

    Commit your local changes

      git add .
      git commit -m ‘Commit msg’
    

    Try to get the changes (will fail)

      git pull
    

    will report something like:

      Pull is not possible because you have unmerged files.
      Please, fix them up in the work tree, and then use 'git add/rm <file>'
      as appropriate to mark resolution, or use 'git commit -a'.
    

    Open the conflict file and fix the conflict. Then:

      git add .
      git commit -m ‘Fix conflicts’
      git pull
    

    will report something like:

      Already up-to-date.
    

More info: https://stackoverflow.com/questions/9529078/how-do-i-used-git-reset-hard-head-to-revert-to-a-previous-commit

Solution 3 - Git

I suspect that what's happened may be that you've deleted the files that you modified (because you didn't care about those changes) and now git is taking the deletion to be a change.

Here is an approach that moves your changes out of your working copy and into the "stash" (retrievable should it actually turn out that you ever need them again), so you can then pull the latest changes down from the upstream.

git stash  
git pull

If you ever want to retrieve your files (potential conflicts with upstream changes and all), run a git stash apply to stick those changes on top of your code. That way, you have an "undo" approach.

Solution 4 - Git

You have to merge your files first. Do a git status to see what are the files that need to be merged (means you need to resolve the conflicts first). Once this is done, do git add file_merged and do your pull again.

Solution 5 - Git

try this code

cd /go/to/path
git pull origin master

Solution 6 - Git

If you just want to throw away everything in your working folder (eg the results of a failed or aborted merge) and revert to a clean previous commit, do a git reset --hard.

Solution 7 - Git

I understand you want to trash your local changes and pull down what's on your remote?

If all else fails, and if you're (quite understandably) scared of "reset", the simplest thing is just to clone origin into a new directory and trash your old one.

Solution 8 - Git

By Running this command you'll get the most recent tag that usually is the version of your project:

git describe --abbrev=0 --tags

Solution 9 - Git

To answer your questions there are simply two steps:-

  1. Pull the latest changes from your git repo using git pull
  2. Clean your local working directory having unstaged changes using git checkout -- . .This will show the latest changes in your local repo from your remote git repo. cleaning all the local unstaged changes.

Please note git checkout -- . will discard all your changes in the local working directory. In case you want to discard any change for selective file use git checkout -- <filename>. And in case you don't want to lose your unstaged changes use git stash as it will clean your local working directory of all the unstaged changes while saving it if you need it in the future.

Solution 10 - Git

It sounds to me like you're having core.autocrlf-problems. core.autocrlf=true can give problems like the ones you describe on Windows if CRLF newlines were checked into the repository. Try disabling core.autocrlf for the repository, and perform a hard-reset.

Solution 11 - Git

If you are using Git GUI, first fetch then merge.

Fetch via Remote menu >> Fetch >> Origin. Merge via Merge menu >> Merge Local.

The following dialog appears.

enter image description here

Select the tracking branch radio button (also by default selected), leave the yellow box empty and press merge and this should update the files.

I had already reverted some local changes before doing these steps since I wanted to discard those anyways so I don't have to eliminate via merge later.

Solution 12 - Git

If the above commands didn't help you use this method:

  1. Go to the git archive where you have Fork
  2. Click Settings> Scroll down and click Delete this repository
  3. Confirm delete
  4. Fork again, and re-enter the git clone
  5. You already have the latest version

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDaveView Question on Stackoverflow
Solution 1 - GitAlex CurtisView Answer on Stackoverflow
Solution 2 - GittvlView Answer on Stackoverflow
Solution 3 - GitKzqaiView Answer on Stackoverflow
Solution 4 - GitAmokrane ChentirView Answer on Stackoverflow
Solution 5 - GitAmirouche ZeggaghView Answer on Stackoverflow
Solution 6 - GitdamianView Answer on Stackoverflow
Solution 7 - GitDan RayView Answer on Stackoverflow
Solution 8 - GitReCatCoderView Answer on Stackoverflow
Solution 9 - Gitmohit srivastavaView Answer on Stackoverflow
Solution 10 - GitkusmaView Answer on Stackoverflow
Solution 11 - GitzarView Answer on Stackoverflow
Solution 12 - GitTrinh HieuView Answer on Stackoverflow