This blog provides the easiest procedure to replace the local version with the remote version on Git.
How to Replace Local Version With Remote Version in Git?
To replace the local version of the branch with the remote version, first, go to the required repository. Then, view all the available branches in your local repository and switch to your desired branch. Next, fetch the remote branches. Lastly, run the “git reset –hard <remote-name>/<branch-name>” command to get the latest version of the remote branch.
To do so, follow the below-presented steps.
Step 1: Go to Git Local Git Repository
Utilize the “cd” command and navigate to the particular Git repository:
Step 2: View All the Local Branches
Next, view the list of all branches by using the following command:
In the below output, the asterisk “*” sign beside the “dev” branch represents the current working branch:
Step 3: Switch Branch
Now, switch to the desired local branch to which you want to replace it with the remote branch version:
As you can see, we have switched to the specified “master” branch:
Step 4: Check Remote URLs
To view the list of all available remote URLs, execute the below-stated command:
Step 5: Fetch the Remote Branch
Then, download the updated version of the remote repository by fetching its content through the “git fetch” command:
Step 6: Replace Local Version With Remote Version
Finally, run the “git reset” command along with the “–hard” option and required remote branch name:
Here, you can see the “HEAD” pointer moved its position to “dd9c220” commit SHA hash:
Step 7: Check Git Log
Check the Git logs to verify whether the local branch is replaced exact as a remote branch or not:
The output below shows that the local branch version is replaced with a remote branch version successfully:
We have efficiently explained the method of replacing the local version with the remote version.
Conclusion
To update the local version with the latest remote version, first, navigate to the local repository. Then, view the list of all existing branches and switch to the targeted branch which needs to be replaced with the remote branch. After that, fetch the remote repository content and run the “git reset –hard <remote-name>/<branch-name>” command to replace the local branch with the remote branch. Lastly, check the Git log to see the changes. This blog explained the method of replacing the local version with the remote version.