EN
Git - pull with force to override / reset local changes in history
2 points
In this article, we want to show how run git pull
command overriding local changes.
Quick solution (on master branch):
xxxxxxxxxx
1
git fetch
2
git reset --hard origin/master
Read the below sections to know much more.
Somene in team made changes in git history or we modified locally repositiry and we want to use code version from remote server.
Console example (in this case conflict occured):
xxxxxxxxxx
1
my-user@ubuntu-pc:~/Projects/my-project$ git pull
2
3
Auto-merging src/themes/light/default.ts
4
CONFLICT (content): Merge conflict in src/themes/light/default.ts
5
Auto-merging src/themes/light/colors.scss
6
Auto-merging src/modules/users/index.tsx
7
CONFLICT (add/add): Merge conflict in src/modules/users/index.tsx
8
Auto-merging src/components/input.tsx
9
Auto-merging src/components/notification.tsx
10
Automatic merge failed; fix conflicts and then commit the result.
11
12
my-user@ubuntu-pc:~/Projects/my-project$
Run git reset --hard
with name of branch making sure you have current version of source code.
Recommended steps:
1. fetch current source code from remote repository using:
xxxxxxxxxx
1
git fetch --all
2. reset changes for specific branch using:
xxxxxxxxxx
1
git reset --hard origin/my-branch-name
Note:
git reset --hard origin/master
if we work on master branch.
Console example:
xxxxxxxxxx
1
my-user@ubuntu-pc:~/Projects/my-project$ git reset --hard origin/bug-fixes
2
3
HEAD is now at e7f21a4 Fixed notification error.
4
my-user@ubuntu-pc:~/Projects/my-project$