How to Reset Local branch to Mirror Remote HEAD Repository in Git ?

0
239
How to Reset Local branch to Mirror Remote HEAD Repository in Git ?
How to Reset Local branch to Mirror Remote HEAD Repository in Git ?

Sync Local Branch Repo with Remote Repo in Github

How to Reset Local branch to Mirror Remote HEAD Repository in Git ?

You can easily do this using any of the two solutions below –

Solution 1:

First run


git fetch origin

git reset --hard origin/master

Next use, command below to delete any untracked files that may exist.


git-clean -f

 

Solution 2:

Reset to the previously fetched 

HEAD

 of the corresponding upstream branch:


git reset --hard @{u}

What is @{u} ? It means upstream.

The advantage of specifying 

@{u}

 or its verbose form 

@{upstream}

 is that the name of the remote repo and branch don’t have to be explicitly specified.

Next we need to remove any untracked files –


git clean -df

Finally, Sync and get the latest changes:


git pull
How to Reset Local branch to Mirror Remote HEAD Repository in Git ?
How to Reset Local branch to Mirror Remote HEAD Repository in Git ?

You may also be interested in – 

Article: How to delete untracked files from current working tree Github?

and other Git related articles and Solutions here