CARVIEW |
Guides: Changing Your Origin
Changing Your Origin
If you were hosting your Git repo somewhere else before switching over to GitHub, you will need to change your origin so pushes will go to the new repo.
Changing from repo.or.cz
Many people might be coming from another popular public repository, repo.or.cz
, so we'll use that as an example.
You will need to edit your .git/config
file to change the url
variable to be the new repo. Where it used to be something like this:
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = git+ssh://repo.or.cz/srv/git/myproject.git fetch = +refs/heads/*:refs/remotes/origin/* push = refs/heads/master:refs/heads/master
You will now have to change it to something like this:
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = git@github.com:username/myproject.git fetch = +refs/heads/*:refs/remotes/origin/* push = refs/heads/master:refs/heads/master
Multi-Origin
'origin' is just a default name, there is no actual reason to use it - anything else can be used just as easily. In fact, it's often helpful to have many remotes that you can push to and/or pull from. Here is an alternate .git/config
file that will allow you to push to either github or repo.or.cz as you wish.
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "public"] url = git+ssh://repo.or.cz/srv/git/myproject.git fetch = +refs/heads/*:refs/remotes/public/* push = refs/heads/master:refs/heads/master [remote "github"] url = git@github.com:username/myproject.git fetch = +refs/heads/*:refs/remotes/github/* push = refs/heads/*:refs/heads/*
That will allow you to run this command to push to your repo.or.cz account:
~: git push public
And this to push to your github account:
~: git push github