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
564
votes
9 answers

Git: How to update/checkout a single file from remote origin master?

The scenario: I make some changes in a single file locally and run git add, git commit and git push The file is pushed to the remote origin master repository I have another local repository that is deployed via Capistrano with the "remote_cache"…
foresth
  • 5,823
  • 4
  • 17
  • 8
518
votes
8 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
  • 182,215
  • 215
  • 566
  • 871
516
votes
21 answers

How can I check out a GitHub pull request with git?

I'd like to check out a previously created pull request (created via GitHub web interface). I searched and found different places where a refs/pull or refs/pull/pr But when I add fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to the git config…
GarfieldKlon
  • 11,170
  • 7
  • 31
  • 33
477
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
  • 99,403
  • 23
  • 97
  • 120
455
votes
8 answers

Git: can't undo local changes (error: path ... is unmerged)

I have following working tree state $ git status foo/bar.txt # On branch master # Unmerged paths: # (use "git reset HEAD ..." to unstage) # (use "git add/rm ..." as appropriate to mark resolution) # # deleted by us: …
mklhmnn
  • 4,770
  • 2
  • 16
  • 8
419
votes
14 answers

How to checkout in Git by date?

I am working on a regression in the source code. I'd like to tell Git: "checkout the source based on a parameterized date/time". Is this possible? I also have staged changes in my current view that I don't want to lose. Ideally, I would like to…
Amir Afghani
  • 37,814
  • 16
  • 84
  • 124
414
votes
16 answers

Switch branch and ignore any changes without committing

I was working on a git branch and was ready to commit my changes, so I made a commit with a useful commit message. I then absentmindedly made minor changes to the code that are not worth keeping. I now want to change branches, but git gives…
Daniel Farrell
  • 9,316
  • 8
  • 39
  • 62
405
votes
12 answers

What to do with commit made in a detached head

Using git I made something like this git clone git checkout {a rev number tree rev before} (here I started to be in a detached head state) //hacking git commit //hacking git commit (some commit where made on origin/master) git pull (which does…
benzen
  • 6,204
  • 4
  • 25
  • 37
399
votes
13 answers

How can I switch to another branch in git?

Which one of these lines is correct? git checkout 'another_branch' or git checkout origin 'another_branch' or git checkout origin/'another_branch' And what is the difference between them?
Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150
388
votes
5 answers

How to 'git pull' without switching branches (git checkout)?

I'm used to running git pull and other commands from within a branch I'm working on. But I have set up a development server that several people work on, so I don't want to have to switch branches when I do it. If I want to update an existing branch…
Diana Saunders
  • 3,889
  • 2
  • 12
  • 3
380
votes
7 answers

What's the difference between Git Revert, Checkout and Reset?

I am trying to learn how to restore or rollback files and projects to a prior state, and don't understand the difference between git revert, checkout, and reset. Why are there 3 different commands for seemingly the same purpose, and when should…
haziz
  • 12,994
  • 16
  • 54
  • 75
336
votes
6 answers

Git, How to reset origin/master to a commit?

I reset my local master to a commit by this command: git reset --hard e3f1e37 when I enter $ git status command, terminal says: # On branch master # Your branch is behind 'origin/master' by 7 commits, and can be fast-forwarded. # (use "git pull"…
Hesam
  • 52,260
  • 74
  • 224
  • 365
325
votes
10 answers

How to get back to most recent version in Git?

I have recently moved from SVN to Git and am a bit confused about something. I needed to run the previous version of a script through a debugger, so I did git checkout and did what I needed to do. Now I want to get back to…
Nathan Long
  • 122,748
  • 97
  • 336
  • 451
325
votes
3 answers

Meaning of Git checkout double dashes

What is the meaning of the double dashes before the file name in this git command? git checkout --ours -- path/to/file.txt git checkout --theirs -- path/to/file.txt Are they mandatory? Is it equivalent to git checkout --ours path/to/file.txt git…
mottalrd
  • 4,390
  • 5
  • 25
  • 31
312
votes
4 answers

Difference between git checkout --track origin/branch and git checkout -b branch origin/branch

Does anybody know the difference between these two commands to switch and track a remote branch? git checkout -b branch origin/branch git checkout --track origin/branch I think both keep track of the remote branch so I can push my changes to the…
yorch
  • 7,170
  • 8
  • 32
  • 38
1
2
3
72 73