CodePudding user response:
Cloning a repository clones all of the commits and none of the branches.
That's OK, because those are their branches. In your clone, you will get your own branches. What matters aren't the branches, but rather the commits—and you already got all the commits.
If you'd like to create your own branch name that matches someone else's branch name, after you've cloned someone else's repository, Git makes that easy:
git switch gh-pages
for instance will create for you a new branch, gh-pages
, referring to the same commit that your Git is remembering via origin/gh-pages
.
You don't need a branch name to use a commit. You can use a commit directly, in what Git calls detached HEAD mode. The drawback to using detached HEAD mode is that if you make any new commits, you may not be able to find them again later. That's because the way we find commits, in general, is to use branch names.
So remember: in Git, the purpose of a branch name is to help you find particular commits. It's the commits, not the branch name, that matter. If you had some other way to find them—besides branch names—you could use that instead, but branch names are the convenient way to find the commits. Clones do not share branch names, though. They only share commits: when you make new commits in your repository, you will need to use git push
to send those commits to someone else (some other Git repository).
When you do send those commits to another Git repository, you'll want to ask them—the other Git repository—to create or update a branch name in their repository, so that they can find the commits. But again, it's the commits that actually matter. When you think about Git, you should think about commits, not branches.