From 2a4379ceea9fa2626b6b4242ea03e36190d3861d Mon Sep 17 00:00:00 2001 From: Waldir Pimenta Date: Sun, 30 Apr 2017 11:17:03 +0100 Subject: [PATCH] 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 --- pages/common/git-checkout.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pages/common/git-checkout.md b/pages/common/git-checkout.md index d886e74fac..7d45d729b9 100644 --- a/pages/common/git-checkout.md +++ b/pages/common/git-checkout.md @@ -6,10 +6,14 @@ `git checkout -b {{branch_name}}` -- Switch to an existing local or remote branch: +- 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 .`