Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community that shares solutions with each other.

If you think you have something to add here.

you are welcome with your fresh ideas - List Articles

Git - pull with force to override / reset local changes in history

0 contributions
2 points

In this article we are going to look on how to run git pull command with overriding local changes.

1. Problem overview:

Somene in team made changes in git history or we modified locally repositiry and we want to use code version from remote server.

Console print (in this case conflict occured):

my-user@ubuntu-pc:~/Projects/my-project$ git pull
Auto-merging src/themes/light/default.ts
CONFLICT (content): Merge conflict in src/themes/light/default.ts
Auto-merging src/themes/light/colors.scss
Auto-merging src/modules/users/index.tsx
CONFLICT (add/add): Merge conflict in src/modules/users/index.tsx
Auto-merging src/components/input.tsx
Auto-merging src/components/notification.tsx
Automatic merge failed; fix conflicts and then commit the result.

2. Problem solution

Run git reset --hard with name of branch making sure you have current version of source code.

1. Fetch current source code from remote repository:

git fetch --all

2. Reset changes for specific branch:

git reset --hard origin/my-branch-name

Note: git reset --hard origin/master if we work on master branch.

Console print:

my-user@ubuntu-pc:~/Projects/my-project$ git reset --hard origin/bug-fixes 
HEAD is now at e7f21a4 Fixed notification error.


0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more