1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-04-29 23:24:55 +02:00
tldr/pages/common/git-checkout.md
Waldir Pimenta 2a4379ceea git-checkout: correct checkout of remote branch (#1359)
As described in http://stackoverflow.com/a/9537923 (paraphrased below):

> You need to create a local branch that tracks a remote branch.
> The following command will create a local branch
> tracking the remote branch of the same name.
> When you push your changes the remote branch will be updated.
>
> `git checkout --track [remotename]/[branch]`
>
> This is a shorthand for `git checkout -b [branch] [remotename]/[branch]`.
>
> For git 1.7.2.3 and higher this is enough: `git checkout daves_branch`
>
> Note that with recent git versions,
> **this will command not create a local branch and will put you in a 'detached HEAD' state.**
> If you want a local branch, use the --track option.
> Full details here: http://git-scm.com/book/en/v2/Git-Branching-Remote-Branches#Tracking-Branches
2017-04-30 11:17:03 +01:00

23 lines
513 B
Markdown

# git checkout
> Checkout a branch or paths to the working tree.
- Create and switch to a new branch:
`git checkout -b {{branch_name}}`
- Switch to an existing local branch:
`git checkout {{branch_name}}`
- Switch to an existing remote branch:
`git checkout --track {{remote_name}}/{{branch_name}}`
- Undo unstaged local modification:
`git checkout .`
- Replace a file in the current working directory with the version of it committed in a given branch:
`git checkout {{branch_name}} -- {{file_name}}`