0

What I think I know

When I clone or fetch from a remote repository, the name of the remote is prefixed to the names of the branches imported from this remote.
For instance, if the remote is called origin in my repository, then after cloning the remote's master branch is called origin/master in my repository.

This behavior makes sure that there are never name clashes between imported branches to branches that already exist in my repository (whether they were created locally or imported from other repositories).

What I don't know (i.e. my question)

When I push to a remote repository, is my repository name prefixed (in the remote repository) to the names of the branches that get pushed?

If not, how are branch name clashes avoided?

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
Evan Aad
  • 5,699
  • 6
  • 25
  • 36
  • 1
    Branch name clashes *aren't* avoided, as you can find out by creating branches with the same name in two places and trying to push both to the same remote. See e.g. http://stackoverflow.com/questions/31631726/how-does-git-deal-with-identical-branch-names-from-two-different-remote-repo and http://stackoverflow.com/questions/17359978/why-has-git-allowed-me-to-create-two-branches-with-the-same-name for more on separate local and remote branches. – jonrsharpe Apr 07 '17 at 06:57

1 Answers1

1

What I think I know

When I clone or fetch from a remote repository, the name of the remote is prefixed to the names of the branches imported from this remote.

For instance, if the remote is called origin in my repository, then after cloning the remote's master branch is called origin/master in my repository.

Its not exactly like this.
When you clone a git repository git you get reference to all the branches but only master is checked out

enter image description here

Every time you checkout a branch git add a track branch to it

enter image description here

When I push to a remote repository, is my repository name prefixed (in the remote repository) to the names of the branches that get pushed?

Whenever you type push git use an internal mechanism called refspec

refspec

The format of the refspec is an optional +, followed by <src>:<dst>, where <src> is the pattern for references on the remote side and <dst> is where those references will be written locally.
The + tells Git to update the reference even if it isn’t a fast-forward.

More reading:
https://www.atlassian.com/git/tutorials/refs-and-the-reflog#refspecs

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167