Questions tagged [git-checkout]

Checkout a branch or file to the current working tree in a Git repo.

git checkout is used to update files in the current working tree to a specific version in the index or specified branch.

To restore a file to the version in the index:

git checkout -- <filename>

Popular questions

See also

References

$ git checkout --help
975 questions
7624
votes
41 answers

How do I revert a Git repository to a previous commit?

How do I revert from my current state to a snapshot made on a certain commit? If I do git log, then I get the following output: $ git log commit a867b4af366350be2e7c21b8de9cc6504678a61b` Author: Me Date: Thu Nov 4 18:59:41 2010…
Crazy Serb
  • 76,496
  • 8
  • 33
  • 46
7300
votes
35 answers

How do I check out a remote Git branch?

Somebody pushed a branch called test with git push origin test to a shared repository. I can see the branch with git branch -r. Now I'm trying to check out the remote test branch. I've tried: git checkout test which does nothing git checkout…
Juri Glass
  • 76,369
  • 8
  • 31
  • 46
4913
votes
33 answers

How can I reset or revert a file to a specific revision?

I have made some changes to a file which has been committed a few times as part of a group of files, but now want to reset/revert the changes on it back to a previous version. I have done a git log along with a git diff to find the revision I need,…
Hates_
  • 58,801
  • 6
  • 28
  • 37
2974
votes
28 answers

How to find and restore a deleted file in a Git repository

Say I'm in a Git repository. I delete a file and commit that change. I continue working and make some more commits. Then, I find I need to restore that file. I know I can checkout a file using git checkout HEAD^ foo.bar, but I don't really know when…
avdgaag
  • 38,646
  • 7
  • 27
  • 26
2145
votes
14 answers

How do I revert all local changes in Git managed project to previous state?

I have a project in which I ran git init. After several commits, I did git status which told me everything was up to date and there were no local changes. Then I made several consecutive changes and realized I wanted to throw everything away and…
Jacques René Mesrine
  • 41,077
  • 24
  • 60
  • 99
1503
votes
11 answers

How to get just one file from another branch

I am using git and working on master branch. This branch has a file called app.js. I have an experiment branch in which I made a bunch of changes and tons of commits. Now I want to bring all the changes done only to app.js from experiment to master…
Nick Vanderbilt
  • 31,184
  • 26
  • 77
  • 102
851
votes
11 answers

Rollback to an old Git commit in a public repo

How can I go about rolling back to a specific commit in git? The best answer someone could give me was to use git revert X times until I reach the desired commit. So let's say I want to revert back to a commit that's 20 commits old, I'd have to…
David
  • 8,917
  • 5
  • 23
  • 31
810
votes
8 answers

Is there any way to git checkout previous branch?

I sort of want the equivalent of cd - for git. If I am in branch master and I checkout foo, I would love to be able to type something like git checkout - to go back to master, and be able to type it again to return to foo. Does anything like this…
Matt Briggs
  • 38,679
  • 14
  • 86
  • 125
724
votes
18 answers

Merge, update, and pull Git branches without using checkouts

I work on a project that has 2 branches, A and B. I typically work on branch A, and merge stuff from branch B. For the merging, I would typically do: git merge origin/branchB However, I would also like to keep a local copy of branch B, as I may…
charles
  • 9,897
  • 3
  • 28
  • 44
611
votes
5 answers

What is git tag, How to create tags & How to checkout git remote tag(s)

when I checkout remote git tag use command like this: git checkout -b local_branch_name origin/remote_tag_name I got error like this: error: pathspec `origin/remote_tag_name` did not match any file(s) known to git. I can find remote_tag_name when…
Ryanqy
  • 6,722
  • 3
  • 12
  • 23
564
votes
7 answers

Unstage a deleted file in git

Usually, to discard changes to a file you would do: git checkout -- What if the change I want to discard is deleting the file? The above line would give an error: error: pathspec '' did not match any file(s) known to git. What command…
lurscher
  • 23,085
  • 26
  • 113
  • 178
543
votes
24 answers

How to get the latest tag name in current branch in Git?

What's the simplest way to get the most recent tag in Git? git tag a HEAD git tag b HEAD^^ git tag c HEAD^ git tag output: a b c Should I write a script to get each tag's datetime and compare them?
culebrón
  • 28,179
  • 18
  • 66
  • 97
492
votes
21 answers

How to sparsely checkout only one single file from a git repository?

How do I checkout just one file from a git repo?
Arthur Ulfeldt
  • 87,736
  • 24
  • 197
  • 278
471
votes
6 answers

What's the difference between "git reset" and "git checkout"?

I've always thought of git reset and git checkout as the same, in the sense that both bring the project back to a specific commit. However, I feel they can't be exactly the same, as that would be redundant. What is the actual difference between the…
prosseek
  • 155,475
  • 189
  • 518
  • 818
470
votes
11 answers

Git checkout: updating paths is incompatible with switching branches

My problem is related to Fatal Git error when switching branch. I try to fetch a remote branch with the command git checkout -b local-name origin/remote-name but I get this error message: fatal: git checkout: updating paths is incompatible with…
Ikke
  • 90,705
  • 23
  • 91
  • 118
1
2 3
64 65