How to force pull in git , to override local file changes ?
Today’s post we are going to learn very routine issue as developers we all face this issue. How to force pull the changes from master branch and override the local changes .
git reset --hard HEAD
git pull
above command will remove — uncommited changes only
What if i want to remove untracked file of git ?
# WARNING: this can't be undone!
git reset --hard HEAD
git clean -f -d
git pull
WARNING: git clean
deletes all your untracked files/directories and can't be undone.
Consider using -n
(--dry-run
) flag first. This will show you what will be deleted without actually deleting anything:
git clean -n -f -d
Example output will be like
Would remove untracked-file1.txt
Would remove untracked-file2.txt
Would remove untracked/folder
...
other better way is to
git clean
To delete all untracked files and then continue with the usual git pull
If you want to remove untracked directories in addition to untracked files:
git clean -fd
Productive Trick :
git pull --rebase
This above command is the most useful command in my Git life which saved a lot of time.
Before pushing your newly commit to server, try this command and it will automatically synchronise the latest server changes (with a fetch + merge) and will place your commit at the top in the Git log. There isn’t any need to worry about manual pull/merge.
what actually above command do ?
git fetch origin
git rebase origin/foo
Find details in What does “git pull — rebase” do?.
Read More blogs on