Difference between revisions of "Git/checkout"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< Git
Jump to navigation Jump to search
(→‎Links: local manpage)
(copying a single file)
 
Line 7: Line 7:
  
 
==Options==
 
==Options==
* <code>git {{l/same|checkout}} -b {{arg|name}}</code> does the same thing as executing these two commands:
+
* <code>git {{l/same|checkout}} -b {{arg|branch name}}</code> does the same thing as executing these two commands:
** <code>git {{l/same|branch}} {{arg|name}}</code> creates a new branch called "name", pointing at the current {{l/same|HEAD}} revision
+
** <code>git {{l/same|branch}} {{arg|branch name}}</code> creates a new branch called "name", pointing at the current {{l/same|HEAD}} revision
** <code>git {{l/same|checkout}} {{arg|name}}</code>  moves {{l/same|HEAD}} to point to the branch called "name"
+
** <code>git {{l/same|checkout}} {{arg|branch name}}</code>  moves {{l/same|HEAD}} to point to the branch called "name"
 
+
* <code>git {{l/same|checkout}} {{arg|branch name}} {{arg|filespec}}</code> copies the version of {{arg|filespec}} from the {{arg|branch name}} branch over to the current branch
 +
** {{arg|filespec}}: for a path relative to the git repository root, do not prefix with a <code>/</code>
 
==Links==
 
==Links==
 
===Reference===
 
===Reference===
 
* {{l/manpage|git-checkout|manpage @ HTYP}}
 
* {{l/manpage|git-checkout|manpage @ HTYP}}
 
* [https://git-scm.com/docs/git-checkout git-scm] - Switch branches or restore working tree files
 
* [https://git-scm.com/docs/git-checkout git-scm] - Switch branches or restore working tree files

Latest revision as of 05:44, 8 November 2018

About

The git checkout command allows you to switch branches. If you've got incomplete changes you want to set aside before switching branches, use git stash.

When you do a checkout, all the files in your working folder-tree are replaced by a snapshot of that tree as saved when you last committed to that branch.

If there are any uncommitted changes, git will warn you of this and refuse to do the checkout. You can either commit or stash to resolve this.

Options

  • git checkout -b <branch name> does the same thing as executing these two commands:
    • git branch <branch name> creates a new branch called "name", pointing at the current HEAD revision
    • git checkout <branch name> moves HEAD to point to the branch called "name"
  • git checkout <branch name> <filespec> copies the version of <filespec> from the <branch name> branch over to the current branch
    • <filespec>: for a path relative to the git repository root, do not prefix with a /

Links

Reference