in Technology by
How to Reset local repository branch to be just like remote repository HEAD?

1 Answer

0 votes
by

Setting your branch to exactly match the remote branch can be done in two steps:

git fetch origin
git reset --hard origin/master

Update @2020 (if you have main branch instead of master in remote repo)

git fetch origin
git reset --hard origin/main 

If you want to save your current branch's state before doing this (just in case), you can do:

git commit -a -m "Saving my work, just in case"
git branch my-saved-work

Now your work is saved on the branch "my-saved-work" in case you decide you want it back (or want to look at it later or diff it against your updated branch).

Note that the first example assumes that the remote repo's name is "origin" and that the branch named "master" in the remote repo matches the currently checked-out branch in your local repo.

Related questions

0 votes
    How to push a new local branch to a remote Git repository and track it too?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    How can we create a new branch on both local and remote?...
asked Jan 8, 2021 in Technology by JackTerrance
0 votes
    What is the command to delete a branch in your remote repository? A. git delete branchname B. git branch -d branchname C. git push origin -d branchname D. None of the options...
asked Dec 20, 2022 in Technology by JackTerrance
0 votes
    What is the command to delete a branch in your remote repository? (1)git branch -d branchname (2)None of the options (3)git push origin -d branchname (4)git delete branchname...
asked Oct 26, 2020 in Technology by JackTerrance
0 votes
    What is the command to delete a branch in your remote repository? (1)git branch -d branchname (2)None of the options (3)git push origin -d branchname (4)git delete branchname...
asked Oct 26, 2020 in Technology by JackTerrance
0 votes
    we are using git in Team Foundation Service, and we are trying to find a way to delete a remote ... /DefaultCollection/_git/Xxxxxx' Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I pulled a project from GitHub a few days ago. I've since discovered that there are several forks on GitHub, ... those forks I pulled? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    What are the benefit of storing JARS/external dependencies in the local repository instead of a remote one?...
asked May 4, 2021 in Technology by Editorial Staff
0 votes
    Has anyone managed to run an ipynb Python notebook using a local kernel but connecting to a remote GitHub ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    What does the command git reset –hard HEAD ~3 do? A. Merges the last 3 commits to the master B. Discards ... nothing D. Resets the head to 3 commits before the current commit...
asked Dec 23, 2022 in Technology by JackTerrance
0 votes
    What does the command Git reset –- soft HEAD^ perform? A. Moves commit to one after current head B. Moves commit ... . Moves commit to the first head D. None of the options...
asked Dec 21, 2022 in Education by JackTerrance
0 votes
    How to rename and remove branch in remote Git?...
asked Aug 24, 2021 in Technology by JackTerrance
0 votes
    How can we create a remote Git branch?...
asked Jan 8, 2021 in Technology by JackTerrance
0 votes
    How can we check out a remote Git branch?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    I created a local branch that I want to 'push' upstream. There is a similar question here on Stack ... the upstream repository? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
...