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
47
votes
3 answers

Is there a difference between "git reset --hard hash" and "git checkout hash"?

While reset and checkout have different usages most of the time, I can't see what difference there is between these two. There probably is one or nobody would have bothered adding a --hard option to do something the basic checkout can do. Maybe…
Bite code
  • 578,959
  • 113
  • 301
  • 329
46
votes
5 answers

How to checkout a remote branch in Git?

Someone pushed a "new feature" branch to the shared repo: git push -u new_feature_branch Now, I would like to create a copy of this branch on my local machine in order to test the new feature. What would be the easiest way to do this? (Do I need to…
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
42
votes
1 answer

git checkout --ours does not remove files from unmerged files list

Hi I need to merge two branches like this. This is just an example what is happening, I work with hundreds of files which need resolution. git merge branch1 ...conflicts... git status .... # Unmerged paths: # (use "git add/rm ..." as…
Charlestone
  • 1,248
  • 1
  • 13
  • 27
41
votes
0 answers

Merging Branches Without Checkout

Is there a way to merge a branch into another without checking out either branch? For example, I have branch 'master' checked out, but I want to merge branch-a into branch-b, without leaving master.
markdorison
  • 139,374
  • 27
  • 55
  • 71
39
votes
5 answers

git checkout branch from outside

Problem: I need somehow to checkout an existing branch of a project that is already cloned locally on my file system without being in that particular folder of this project. Solution: I'm trying to do the following: git clone 'github-project-url'…
eistrati
  • 2,314
  • 6
  • 26
  • 35
38
votes
2 answers

git archive fatal: Operation not supported by protocol

I'm trying to checkout part of remote git repository. As recommended here, with help of command git archive --format=zip --remote=http://path_to_repository But I'm getting error message: fatal: Operation not supported by protocol. Unexpected end…
Sly
  • 15,046
  • 12
  • 60
  • 89
37
votes
6 answers

git - getting ALL previous version of a specific file/folder

I want to retrieve all previous version of a specific file in a git repository. I see it is possible to get one specific version with the checkout command, but I want them all. And the git clone command with the depth option doesn't seem to allow me…
max152
  • 505
  • 1
  • 4
  • 6
35
votes
7 answers

git checkout error: cannot create directory: Permission denied

I am facing issues with the git checkout command. Please help. Here is what I did. Created a local directory. Created some files. Initiated a git repo locally. Created a repo in bitbucket & pushed my local repo to bitbucket Created a new branch…
TechiRik
  • 1,893
  • 6
  • 27
  • 37
35
votes
3 answers

Get git current branch/tag name

How can I get the current branch or tag name for my working copy? I have seen references that indicate rev-parse --abbrev-ref HEAD will give branch name, but this doesn't work if the checkout is of a tag, in which case it just returns 'HEAD'. I…
edA-qa mort-ora-y
  • 30,295
  • 39
  • 137
  • 267
35
votes
3 answers

git tries to delete a directory on checkout

Whenever I switch between my branch (Li) to the master branch I get the following message: Deletion of directory 'sys/console/api' failed. Should I try again? (y/n) Anyone knows how do I get rid of this message? I think that in the past I tried to…
user429400
  • 3,145
  • 12
  • 49
  • 68
33
votes
4 answers

To git checkout without overwriting data

How can you git-checkout without overwriting the data? I run git checkout master I get error: Entry 'forms/answer.php' would be overwritten by merge. Cannot merge. This is surprising, since I did not know that Git merges when I git-checkout. I…
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
32
votes
5 answers

Convert an SVN checkout to use git (git-svn)

I work with software that is kept in svn for version control. I would like to use git (git-svn) however the software requires lots of setup and configuration before it can be used. There are tools that take care of all of the setup, including…
Jachin
  • 2,025
  • 2
  • 19
  • 26
32
votes
5 answers

git checkout error: unable to create file

While cloning a git repository from Linux to a Windows system, I am getting the following error in checkout the phase: $ git clone gituser@serveraddr:/git/git_repo.git git_WA Cloning into 'git_WA'... gituser@serveraddr's password: remote:…
rohit
  • 485
  • 1
  • 7
  • 12
32
votes
3 answers

Git checkout second remote branch

I run: git checkout mygithub/master but for some reason, running 'git status' shows "not currently on any branch". Running: git checkout master and then git status, says that I'm now on branch master. Now I want to switch to another branch.…
NoBugs
  • 9,310
  • 13
  • 80
  • 146
30
votes
5 answers

git: fatal: Cannot switch branch to a non-commit '12382'

Someone else on my team created a new git branch, committed and pushed to the usual remote that we work with. When I try to check out this branch, I get this: % git checkout 12382 fatal: Cannot switch branch to a non-commit '12382' I have not had…
zaphodb
  • 485
  • 1
  • 7
  • 12