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
71
votes
2 answers

git: checkout files from another branch into current branch (don't switch HEAD to the other branch)

I want to load a different version of the files that exist in another branch into my current branch. git help checkout says: DESCRIPTION Updates files in the working tree to match the version in the index or the specified tree. If no paths are…
Kache
  • 15,647
  • 12
  • 51
  • 79
68
votes
3 answers

How to pull into not-the-current-branch?

Say my current branch is myfeature. I want to get master up to date. Both git merge git pull always merge into the current branch, as far as I can tell. Is there a way to merge changes from a remote branch (eg, origin/master) into a branch I'm not…
Steve Bennett
  • 114,604
  • 39
  • 168
  • 219
67
votes
6 answers

Git checkout does not change anything

I really like git. At least, I like the idea of git. Being able to checkout my master project as a separate branch where I can change whatever I want without risk of screwing everything else up is awesome. But it's not working. Basically, my…
Josh Kovach
  • 7,679
  • 3
  • 45
  • 62
66
votes
3 answers

Fetch a single tag from remote repository

This command fetches all tags: git fetch origin --tags This command fetches a specific tag: git fetch origin refs/tags/1.0.0 But that doesn't let me do: git checkout tags/2.3.18 How can I fetch a single tag and then perform a checkout?
aleclarson
  • 18,087
  • 14
  • 64
  • 91
66
votes
13 answers

Visual Studio 2015 Git error message "Cannot pull/switch because there are uncommitted changes"

I am having difficulty in doing a pull from origin. I keep getting: "Cannot pull because there are uncommitted changes. Commit or undo your changes before pulling again. See the Output window for details." This also applies to switching branches.…
kwiri
  • 1,399
  • 2
  • 15
  • 22
62
votes
2 answers

How do I intentionally detach HEAD in git?

If I do git checkout HEAD^, I get this: $ git checkout HEAD^ Note: checking out 'HEAD^'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state…
Russell Silva
  • 2,772
  • 3
  • 26
  • 36
61
votes
5 answers

git clone and checkout in a single command

The following is the command I use to checkout a specific commit. git clone git://repo.git/repo123 git checkout I want to do the above in one step - using a git clone command only. The reason why I want to do this is, repo123 is very…
user2731584
  • 926
  • 1
  • 7
  • 17
58
votes
13 answers

error: pathspec 'test-branch' did not match any file(s) known to git

I am a new user of Git. I have forked a repository called Spoon-Knife (available for practicing forking with Git). Then, I cloned it locally by running git clone https://github.com/rohinichoudhary/Spoon-Knife.git This repository contains three…
Rohini Choudhary
  • 2,423
  • 2
  • 21
  • 31
58
votes
4 answers

How can I build a git tag in TeamCity?

I want to provide a git tag to the TeamCity server to build it. I pass the tag (i.e. release_1.1) as a parameter to the job. So inside the job the tag is available as %tag%, but under the Version Control Settings I don't see any way to use this…
js3dev
  • 593
  • 1
  • 4
  • 7
57
votes
7 answers

What's the git equivalent of "svn update -r"?

I'm a recent git convert. It's great to be able to use git-svn to keep my branches locally without disturbing the svn server. There was a bug that existed in the latest version of the code. I wanted to establish a time when it worked so that I could…
fratrik
  • 1,700
  • 2
  • 15
  • 17
56
votes
6 answers

Can I use "git checkout --" on two files?

Is it possible to use git checkout -- on multiple files in order to discard the changes? If so how would I specify multiple files?
John Smith
  • 591
  • 1
  • 4
  • 4
51
votes
4 answers

How to do 'git checkout --theirs' for multiple files (or all unmerged files)

Say I have this after attempting a merge and upon entering git status: # Unmerged paths: # (use "git add/rm ..." as appropriate to mark resolution) # # added by them: myfile1.xhtml # added by them: myfile2.xhtml # added by them:…
isherwood
  • 58,414
  • 16
  • 114
  • 157
49
votes
3 answers

How can I get a list of Git branches that I've recently checked out?

When moving between Git branches I sometimes forget the name of a branch I was recently on. How can I display a list of recently checked out branches/tags/commits in order of checkout?
Jordan Brough
  • 6,808
  • 3
  • 31
  • 31
48
votes
1 answer

Switch current branch in git bare repository

I actually want to remove a branch in the bare repository i am working with, but this task hits a dead end because I cannot switch away from the master repository without a 'work tree' which a bare repository does not have. When I run git branch -d…
Ankur
  • 2,792
  • 3
  • 23
  • 26
48
votes
4 answers

Git "revert" current directory

In Subversion (SVN), it's possible to do svn revert ./* in which the current directory and only the current directory gets reverted. What is the Git equivalent to svn revert in which only the current directory gets reverted? I know that there's git…
pillarOfLight
  • 8,592
  • 15
  • 60
  • 90