Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: checkout all files from a branch (but stay at current branch)

Tags:

git

I can checkout a particular file from a branch into current branch with git checkout branchname filename. How can I checkout all the files in branchname into current branch?

git checkout branchname does not fit my need since that will switch me away from current branch.

git merge branchname does not fit my need since I do not want to create a commit yet.

Thanks!

like image 287
Ying Xiong Avatar asked Nov 26 '14 04:11

Ying Xiong


Video Answer


1 Answers

git reset --hard branchname

Note that this will get rid of any changes you had in the current branch that aren't in the other branch, and any uncommitted changes you might have had laying around. It will keep you on your current branch but change it to point at the commit which branchname refers to.

If you instead want to not change what commit is being pointed at, you could instead just check out the whole tree:

cd `git rev-parse --show-toplevel`
git checkout branchname .

This is the equivalent of running git checkout branchname filename for the entire repository.

like image 75
Amber Avatar answered Sep 21 '22 20:09

Amber