On the naming of remote repos

143 Views Asked by At

Suppose I read an answer such as this one which tells me that the command I want is

git fetch <remote> <sourceBranch>:<destinationBranch>

How do I know what to fill in as <remote>?

I think the simple answer is that it is always the word origin. I think it would only be something other than origin if I had done something special to set up a repo with multiple simultaneous upstreams, or if I had done something special to set up a repo with an upstream named something other than the default origin. (I further suspect that these "doing something specials" are so rarely done in actual practice that the rule, "it's always origin" really is almost universally true. But that's what I'm trying to figure out here.)

I'm unclear whether that magic word origin is a keyword that implicitly expands to whatever this repo's upstream is named, or if origin is the default name that's always chosen for a new repo's upstream, or what.

1

There are 1 best solutions below

0
LeGEC On

To list your existing remotes :

git remote
# or
git remote -v

Check git help remote to see how to manipulate remotes. For example, here is a pretty standard way to set up an upstream remote on a repo you have cloned on github :

# for example, you can access 'origin' through ssh:
git clone [email protected]:myaccount/thatrepo
cd thatrepo
# and 'upstream' through https:
git remote add upstream https://github.com/author/thatrepo

# from then on :
git fetch upstream master
git fetch origin
git log --oneline --graph upstream/master origin/master mybranch
git push origin mybranch
git push origin mybranch:refs/heads/branch-issue-123

# etc ...

The "default" part of origin is that when you run git clone <somerepo>, the remote to <somerepo> is named origin.

You can override this default name using -o|--origin :

git clone -o foobar <somerepo>

Other than that all is pretty explicit.