Skip to content

Instantly share code, notes, and snippets.

@tbnorth
Last active April 25, 2018 19:17
Show Gist options
  • Save tbnorth/4f282287919ba409d7ab to your computer and use it in GitHub Desktop.
Save tbnorth/4f282287919ba409d7ab to your computer and use it in GitHub Desktop.
Git commands to use branches as independent light-weight repositories within a real repository

Note on git commands to use branches as independent light-weight repositories within a real repository.

Assume the remote repo. already exists, e.g. https://example.com/user/a_repo.git. Create a new empty repository and do things there:

git init subrepo
cd subrepo
date >README.md
git add README.md
git commit -am'one file'

To make this repository into an independent (no parent) branch called subthing in the remote repo.

git remote add origin https://example.com/user/a_repo.git
git checkout -b subthing
git push origin subthing

To get just one branch from a remote repo. using these "branch-repositories":

git clone --branch subthing --single-branch https://example.com/user/a_repo.git subthing

https://stackoverflow.com/questions/17714159/how-do-i-undo-a-single-branch-clone

git remote set-branches --add origin [remote-branch]
git fetch origin [remote-branch]:[local-branch]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment