Home > other >  How to pull the branch of remote repo to cover the changes in the local repo
How to pull the branch of remote repo to cover the changes in the local repo

Time:10-17

Git Structure:

1. Local repo:
    (1) main
    (2) test_branch

2. Remote repo:
    (1) main
    (2) test_branch

For some reasons, some contents in test_branch in the local repo are messed up, so I want to pull the test_branch in the remote repo to the test_branch in the local repo to recover the original structure.

Tried:

git checkout test_branch

git pull origin test_branch

But it didn't work.

Also dig other threads :

Git: How do I force "git pull" to overwrite local files?

Tried:

git fetch --all

git branch backup-test_branch

git reset --hard origin/test_branch

But it also didn't work.

Any suggestions are appreciated.

CodePudding user response:

You can always delete your local branch and recover from the remote, try the following:

git checkout main

git branch -D test_branch

git checkout test_branch

To explain what it's doing, it is changing the current branch to main, deleting the local copy of the test_branch and then changing back to the test_branch branch, but now synchronized with the remote one.

  • Related