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
1090 questions
140
votes
11 answers

Switch Git branch without files checkout

Is it possible in Git to switch to another branch without checking out all files? After switching branch I need to delete all files, regenerate them, commit and switch back. So checking out files is just a waste of time (and there are about 14,000…
tig
  • 25,841
  • 10
  • 64
  • 96
139
votes
14 answers

git checkout tag, git pull fails in branch

I have cloned a git repository and then checked out a tag: # git checkout 2.4.33 -b my_branch This is OK, but when I try to run git pull in my branch, git spits out this error: There is no tracking information for the current branch. Please …
alesko
  • 1,821
  • 3
  • 14
  • 18
130
votes
3 answers

What do git checkouts really mean?

What are checkouts in git? I know once you do checkout to a particular branch, the HEAD points to that branch. But what does it really mean? Does it mean I can then work on that branch? If yes, then, without checking out a branch, I am not able to…
activebiz
  • 6,000
  • 9
  • 41
  • 64
128
votes
2 answers

Git checkout - switching back to HEAD

I've been doing my project while at some point I discovered that one thing stopped working. I needed to look up the state of my code when it was working correctly, so I've decided to use git checkout (because I wanted to check-something-out). And so…
asdfgh
  • 2,823
  • 4
  • 21
  • 26
109
votes
3 answers

git checkout master error: the following untracked working tree files would be overwritten by checkout

I have a git repository. It has A B C D E ... commits. Now I want to checkout D as a new branch named Dbranch. So I excute:git checkout D -b Dbranch. And now I want to delete this branch. Firstly I need to switch to master branch , and then use git…
Fei Xue
  • 1,995
  • 5
  • 19
  • 29
106
votes
2 answers

Is it possible to git-checkout a single line instead of the entire file?

If I have modified several lines of a versioned file, is it possible to undo the changes of a line by command-line? Just like I would do for an entire file with: git checkout /path/to/file.extension but doing something like, say git checkout…
LuisVM
  • 2,763
  • 3
  • 20
  • 22
93
votes
6 answers

Is it possible to view multiple git branches at the same time for the same project?

I have 2 branches, which are not ready to be merged yet, but have some complementary logic, which I'd like to review (before merging) Can I check out multiple git branches of the same project? Is it possible?
James Raitsev
  • 92,517
  • 154
  • 335
  • 470
92
votes
4 answers

Git command to checkout any branch and overwrite local changes

Is there a Git command (or a short sequence of commands) that will safely and surely do the following? Get rid of any local changes. Fetch the given branch from origin if necessary Checkout the given branch? Currently I'm stuck with: git fetch…
szeryf
  • 3,197
  • 3
  • 27
  • 28
91
votes
5 answers

Cloning an older version of github repo

I have an Amazon EC2 machine. I would like to clone an older version of github repo on this machine. Normally I use git clone https://linktomyrepo.git How can I clone an older version, say an update from 14 days ago? I can see the exact version I…
Mobie
  • 1,850
  • 4
  • 19
  • 25
86
votes
3 answers

branch and checkout using a single command

Creating and using a new branch involves two commands: $ git branch new_branch_name $ git checkout new_branch_name I tend to forget the latter, which can be annoying. Is there a way to do this using a single command? Perhaps using an alias, or…
MvG
  • 57,380
  • 22
  • 148
  • 276
86
votes
9 answers

Is there a way to use wildcards with git checkout?

What I would like to do is to checkout a single file or a set of files with a common name part like this git checkout myBranch */myFile.md and git checkout myBranch -- */*Test* (not sure about the '--' part) instead of git checkout myBranch…
kostja
  • 60,521
  • 48
  • 179
  • 224
83
votes
5 answers

What is `git checkout --orphan` used for?

I've just discovered git checkout --orphan, but I don't know how to use it. Its help page says it creates a new unparented branch. In the master branch, I've tried git checkout --orphan br, only to see the files in the working directory change to…
jsvisa
  • 2,987
  • 2
  • 24
  • 30
82
votes
1 answer

Git: Checkout all files except one

When I do a git status, I see files like this: modified: dir/A/file.txt modified: dir/B/file.txt modified: dir/C/file.txt modified: dir/D/file.txt What I want to do is to discard changes to all files EXCEPT for dir/C/file.txt I want to do…
Kyle
  • 3,775
  • 6
  • 37
  • 47
81
votes
15 answers

Get back the changes after accidental checkout?

The following was the status of my repo. [~/rails_apps/jekyll_apps/nepalonrails (design)⚡] ➔ gst # On branch design # Changed but not updated: # (use "git add/rm ..." to update what will be committed) # (use "git checkout -- ..." to…
millisami
  • 9,931
  • 15
  • 70
  • 112
74
votes
3 answers

How to get a copy of an older version of a file in a git repository?

I have a version of a .tex file from a number of commits ago that I would like to get a copy of. I have the sha1 hash value for the commit that has the version of that file that I want. I do not want to replace the current version of the file.…
jbranchaud
  • 5,909
  • 9
  • 45
  • 70