Question

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.

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top