Skip to content

Instantly share code, notes, and snippets.

@DavMorr
Last active March 10, 2018 17:20
Show Gist options
  • Save DavMorr/28aff87bc5b70293ec8875067a7ead19 to your computer and use it in GitHub Desktop.
Save DavMorr/28aff87bc5b70293ec8875067a7ead19 to your computer and use it in GitHub Desktop.
git checkout --track [remotename]/[branch] // shorthand for 'git checkout -b [branch] [remotename]/[branch]'

You need to create a local branch that tracks a remote branch. The following command will create a local branch named daves_branch, tracking the remote branch origin/daves_branch. When you push your changes the remote branch will be updated.

For most versions of git:

git checkout --track origin/daves_branch --track is shorthand for git checkout -b [branch] [remotename]/[branch] where [remotename] is origin in this case and [branch] is twice the same, daves_branch in this case.

For git 1.5.6.5 you needed this:

git checkout --track -b daves_branch origin/daves_branch For git 1.7.2.3 and higher this is enough (might have started earlier but this is the earliest confirmation I could find quickly):

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

Borrowed from:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment