Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make my branch be identical to its correspondent remote branch ?

Tags:

git

This post follows my previous post about git pull: Git: What does EXACTLY "git pull" do?

Let's say that I want to do "git pull" to a certain branch and I want that my local copy of this branch will be IDENTICAL to the remote copy of the remote one. How to do it?

like image 949
CrazySynthax Avatar asked Jul 17 '17 08:07

CrazySynthax


2 Answers

Assuming you're already on the branch in question (and it's tracking the upstream correctly), the simplest way is

git fetch && git reset --hard FETCH_HEAD

This uses the special FETCH_HEAD ref so you don't need to type the upstream branch name or anything else.

like image 53
Useless Avatar answered Oct 03 '22 14:10

Useless


This should do the trick:

git fetch
git reset --hard origin/{insert branch name}
git clean -fd

If you want it to really be the same including removing the gitignored stuff, use git clean -fdx.

like image 43
Tim M. Avatar answered Oct 03 '22 14:10

Tim M.