Karl Karl - 2 months ago 3x
Git Question

git command to get remote changes no matter what

I am stuck on that for long time and not able to find solution
I have branch called


I am in folder
with some older revision of master.

Now i want the command which replaces the current content of folder with latest code in remote master.

There can be many cases but i want to ignore all things below

  1. There can be files modified locally

  2. There can be untracked files

  3. There can force push on master with completely new code

  4. There can be untracaked files which are now in master so that when u pull there are chances of merge conflict with remote files

  5. When u do git status it may say

    1. On branch master and uptodate

    2. On branch master ur branch and origin/master has diverged

    3. On branch master , current rebase in progress

    4. You are on detached head state

    5. You on branch dev

So for all those above cases i want to ignore and i just want latest code.

The easiest way is to delete the folder and clone

Another way is below and really thats dirty and don't want to do that

cd /application && git reset --hard && git rebase --abort | true && git checkout master && git fetch origin && git reset --hard origin/master


Your best bet is to check out origin/master. This avoids having to deal with the state of the local master branch and any merge issues.

# Abort a rebase, if any
git rebase --abort

# Fetch the latest from origin
git fetch origin

# Check it out and throw out any changes
git checkout -f origin/master

# Clean out all untracked files.
git clean -dxf