1

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.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
Steve Summit
  • 45,437
  • 7
  • 70
  • 103
  • The name of the remote is *entirely* under your control; it's just a local name *you* give to a URL. `origin` is just the default name given to the remote created automatically by `git clone`. – chepner Aug 31 '22 at 19:05
  • Despite that [`origin` is the default for cloning](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes), I would say the names are usually convention based (e.g. upstream) and depend on your git workflows (forks, direct interaction, ...) – kapsiR Aug 31 '22 at 19:05
  • You can see the list of all currently configured remotes by running `git remote`. You can see details with `git remote -vv` – William Pursell Aug 31 '22 at 20:31
  • Also, the `` here doesn't match [Git's own documentation](https://git-scm.com/docs/git-fetch), which uses `` instead. Of course `` can then be ``, but it can also be an extended Git URL. – torek Sep 01 '22 at 01:03

1 Answers1

2

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 git@github.com: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.

LeGEC
  • 46,477
  • 5
  • 57
  • 104