Reputation: 3501
After git clone, the config in the new repo looks like:
remote.origin.url=<some url>
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
Then, I can execute "git pull" and "git push". But I'm interested in only do "git pull", because I want to push into another repo.
One thing I can do is:
git add remote repo-for-push <some other url>
git push repo-for-push master
But I would like to configure git to use default and distinct repositories for pull and push, i.e:
git pull # pulls from origin
git push # pushes into repo-for-push, avoiding accidental push into the origin
How can this be configured? Thanks in advance.
EDIT:
Basically, I want to setup the default push repo to be different from the default fetch/pull repo.
Upvotes: 34
Views: 12286
Reputation: 38158
In version 1.6.4, Git gained the ability to have a remote pull from one URL and push to another, using the remote.name.pushurl
config setting. I can imagine weird behavior if the push-repository doesn't track the pull-repository, but I suspect Git will just try to fast-forward the push-repository from the current/tracking/matching branch(es) without regard for what it will pull when it asks the remote of the same name.
For instance, if you wanted to pull via anonymous git protocol, but push via SSH (maybe you need a value off a SecurID token or something to authenticate):
[remote "myremote"]
url = git://server/path
pushurl = user@server:/path
Upvotes: 27
Wrap the "git" command in something that eats the push argument. Off the top of my head I wrote this:
~$ cat /usr/local/bin/git #!/bin/bash # git wrapper # prevents pushing to repository declare -a args declare msg='' while [ $# -gt 0 ] do if [ "$1" != 'push' ]; then args=( "${args[@]}" "$1" ) else msg="No pushing" fi shift done if [ ${#msg} -gt 0 ]; then echo "$msg" fi /usr/bin/git "${args[@]}"
Just be sure to have the wrapped command in your path before the "real" git command.
Upvotes: 0
Reputation: 7591
Looks like
git config remote.origin.receivepack /bin/false
Makes push to remote origin fail.
Upvotes: 36
Reputation: 102971
If you could do all of your pushing from another branch, I think you could configure that branch to have its own separate repository to push to:
git checkout master
git branch outbound
git remote add destination <some url>
git config branch.outbound.remote destination
I haven't tried this, and you may need to do some more work to create a complete solution. It also might not work for you, if you have to push from master.
Upvotes: 0
Reputation: 23562
I'm not sure you can actually do this in git today. The implementation of git-fetch (in builtin-fetch.c) and git-push (in builtin-push.c) both call the internal function remote_get(NULL) to identify the default repository to pull-from/push-to.
One option would be to create an alias that specifies your desired repo. For example:
git config --add alias.mypush "push repo-for-push"
Then you could:
git mypush
to push to your desired repo. Not precisely what you want, of course. (You may also consider the --repo argument to push; see http://kerneltrap.org/mailarchive/git/2008/10/7/3537694 for a recent doc update that clarifies the --repo argument.)
Upvotes: 7