Tuesday, September 6, 2016

git: Using the branches in a remote repository

This is more of a personal note -- something that I need to record in order to use git efficiently.

If you git clone a repository in (e.g. from GitHub), you generally end up on the 'master' or 'origin' branches, assuming that you accept the default nomenclature for referring to a remote repository. To show the other branches available to you:
git remote show [origin]
or
git ls-remote
To show you what you are currently tracking:
git branch -vv
You can then switch to one of the remote branches shown in ls-remote:
git checkout remote_branch
You may find that git warns you about untracked files that are present that may be overwritten by changing the branch.

Assuming you have a bunch of untracked files or cruft that you are certain that don't need and you want to discard:
git clean -d -fx ""
... and then you can proceed with the checkout.

No comments: