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
308
votes
8 answers

How can I move HEAD back to a previous location? (Detached head) & Undo commits

In Git, I was trying to do a squash commit by merging in another branch and then resetting HEAD to the previous place via: git reset origin/master But I need to step out of this. How can I move HEAD back to the previous location? I have the SHA-1…
timpone
  • 19,235
  • 36
  • 121
  • 211
286
votes
7 answers

Show which git tag you are on?

I'm having trouble finding out which tag is currently checked out. When I do: git checkout tag1 git branch I can't seem to find out which tag I'm on. It only logs: * (no branch) master Is it possible to find out which tags are checked out? In…
grm
  • 5,197
  • 5
  • 29
  • 35
285
votes
4 answers

Restore file from old commit in git

I have an old commit that I did a few weeks ago. I want to restore only a single file from that commit. What do I do?
Varun Achar
  • 14,781
  • 7
  • 57
  • 74
283
votes
24 answers

Retrieve a single file from a repository

What is the most efficient mechanism (in respect to data transferred and disk space used) to get the contents of a single file from a remote git repository? So far I've managed to come up with: git clone --no-checkout --depth 1…
Theozaurus
270
votes
17 answers

Git push error: Unable to unlink old (Permission denied)

In the remote server I have a post-receive hook set up in order to make a git checkout of my repository: #!/bin/sh GIT_WORK_TREE=/var/www/ git checkout -f But when I make a push from my local machine to the git repository in the server, I…
rfc1484
  • 9,441
  • 16
  • 72
  • 123
259
votes
7 answers

What is the difference between "git branch" and "git checkout -b"?

I used git checkout -b to create a new branch. I think that git branch does the same thing. How do these two commands differ, if they differ at all?
Adrien Joly
  • 5,056
  • 4
  • 28
  • 43
255
votes
10 answers

Git: "Not currently on any branch." Is there an easy way to get back on a branch, while keeping the changes?

So I've done some work in the repository and when I'm about to commit I realize that I'm not currently on any branch. This happens a lot when working with submodules and I am able to solve it, but the process is tedious and I've been thinking that…
Erik B
  • 40,889
  • 25
  • 119
  • 135
219
votes
10 answers

error: Your local changes to the following files would be overwritten by checkout

This question is similar to this one, but more specific. I have a project with two branches: staging and beta. I develop on staging, and use the master branch to fix bugs. So if I'm working on staging and I see an error, I change to master…
Manolo
  • 24,020
  • 20
  • 85
  • 130
214
votes
7 answers

Why does git-rebase give me merge conflicts when all I'm doing is squashing commits?

We have a Git repository with over 400 commits, the first couple dozen of which were a lot of trial-and-error. We want to clean up these commits by squashing many down into a single commit. Naturally, git-rebase seems the way to go. My problem is…
Ben Hocking
  • 7,790
  • 5
  • 37
  • 52
206
votes
15 answers

"Cannot update paths and switch to branch at the same time"

I sometimes use the checkout -b option to create a new branch, check it out at the same time and set up tracking in one command. In a new environment, I get this error: $ git checkout -b test --track origin/master fatal: Cannot update paths and…
marekful
  • 14,986
  • 6
  • 37
  • 59
203
votes
5 answers

git stash blunder: git stash pop and ended up with merge conflicts

I did a git stash pop and ended up with merge conflicts. I removed the files from the file system and did a git checkout as shown below, but it thinks the files are still unmerged. I then tried replacing the files and doing a git checkout again and…
Chirag Patel
  • 5,819
  • 8
  • 35
  • 38
175
votes
5 answers

git checkout all the files

How can I get rid of all the changes in all the files of my repository? Say I am in a branch and I did some changes. git status returns a set of files in the "Changes not staged for commit" and I notice I would like to get rid of all of these…
fedorqui
  • 275,237
  • 103
  • 548
  • 598
156
votes
4 answers

Git change branch when file of same name is present

I have in my git repo, a file named xyz. Coincidently, I also have a branch named xyz. Presently I am on master, but I want to checkout to branch xyz. The command to be used is simple $ git checkout xyz But this would checkout the file xyz to the…
venky
  • 2,141
  • 3
  • 16
  • 20
152
votes
2 answers

How can I print the log for a branch other than the current one?

I'm on a branch with some changes. Changing branch is a pain as some files are locked by processes, so to change branch I'd have to stop all the processes which have locks, then stash the changes before checking out the other branch to see its…
BanksySan
  • 27,362
  • 33
  • 117
  • 216
146
votes
11 answers

Restore a deleted folder in a Git repo

I have deleted all the contents inside a folder and the folder is empty. I still had a copy in my remote repo. But when I did a git pull it didn't put back the deleted files isn't is supposed to do that? So I did some research and saw that you can…
json2021
  • 2,146
  • 2
  • 14
  • 28
1 2
3
72 73