0

I have my remote origin set to the repo I cloned from and me set to my fork. I have push.default set to current. I'd like the default remote for push to default to me. I know I can do:

git push -u me

to set the remote persistently to me (for the current branch). But, inevitably, I forget to do that the first time I push. What I want is for:

git push

to default the remote repo to me for any branch. However the documentation says:

When the command line does not specify where to push with the <repository> argument, branch.*.remote configuration for the current branch is consulted to determine where to push. If the configuration is missing, it defaults to origin.

I'd like it to not default to origin. I've looked at Why do I need to do `--set-upstream` all the time? (and others) but don't seem to find my answer there.

Community
  • 1
  • 1
George Shaw
  • 1,771
  • 1
  • 18
  • 32
  • What about changing the URL of origin instead? – SzG Apr 17 '14 at 20:17
  • We have git on the web servers and the Rails apps run from the repos. For these there is only origin. I'd like to keep the nomenclature consistent across the live repos and the development systems. – George Shaw Apr 17 '14 at 20:26

1 Answers1

3

With the command below

git remote set-url --push origin <URL-of-me>

git will still default to repo origin, but when pushing, it will use the URL you've supplied. When pulling/fetching it will still use the URL you cloned from.

But you probably want to push to a test-system by default, and be explicit when pushing to the production server. A cleaner solution for that:

git clone <production-URL>
cd <project>
git remote set-url origin <test-URL>
git remote add production <production-URL>

After this

git push

will push to the test site and

git push production

will push to the production site (the original origin).

SzG
  • 12,333
  • 4
  • 28
  • 41
  • Making origin two different URLs is a bit unattractive, but it does work nicely. At one client it is extremely rare that I would ever push to origin, but since I have permissions to do so it could happen by accident (and has). At another client it is infrequent, but using another remote name, as you show, allows access. Here, we use GitHub so the live servers pull from there and are not pushed to directly. Can this be set globally rather than for each repo? – George Shaw Apr 17 '14 at 21:00
  • The remote set-up is not part of the repo, it's stored in the configuration of each, so it's not propagating when cloning/fetching/pushing. Since you called your test site `me`, I guess the setup is different for each client, so there seems to be no point. – SzG Apr 18 '14 at 05:49
  • I realized that after I typed it, but I have about two dozen repos I work on, so I was trying to find a way to be lazy. Thanks! – George Shaw Apr 18 '14 at 18:56