I need to change the url for an remote repository, so I was looking at the docs at https://git-scm.com/docs/git-remote but when I do:
git remote set-url [email protected]:gitusername/repository.git
I get the message usage: git remote set-url [--push] <name> <newurl> [<oldurl>]
I do not really understand, should I type:
git remote set-url --push gitusername [email protected]:gitusername/repository.git
or what is <name>
standing for? And should I include the old url?
UPDATE
So when I type:
git remote set-url --push origin [email protected]:gitusername/repository.git
And after that type git remote -v
I get this:
origin [email protected]:oldusername/oldrepo.git (fetch)
origin [email protected]:gitusername/repository.git (push)
How can I change the fetch?
Create a new, empty Git repository on your remote server. Obtain the git remote add URL for the remote repository and add credentials if needed. Run the git remote add origin command from your local repository with the --set-upstream and the name of the active branch to push.
If you've copied a project from Github, it already has an origin. You can view that origin with the command git remote -v, which will list the URL of the remote repo.
A remote URL is Git's fancy way of saying "the place where your code is stored." That URL could be your repository on GitHub, or another user's fork, or even on a completely different server. You can only push to two types of URL addresses: An HTTPS URL like https://github.com/user/repo.git.
You need to set the URL for an existing remote:
git remote set-url origin [email protected]:gitusername/repository.git
Using the command above will update both the fetch and push URLs.
Using --push
will only update the push URL:
git remote set-url --push origin [email protected]:gitusername/repository.git
git remote -v
origin [email protected]:oldusername/oldrepo.git (fetch)
origin [email protected]:gitusername/repository.git (push)
After this point, there is now a separate entry in .git/config
:
[remote "origin"]
url = [email protected]:oldusername/oldrepo.git
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = [email protected]:gitusername/repository.git
Now, because there are separate entries, using set-url
without --push
will only update fetch, instead of both:
git remote set-url origin [email protected]:thirdusername/thirdrepository.git
git remote -v
origin [email protected]:thirdusername/thirdrepository.git (fetch)
origin [email protected]:gitusername/repository.git (push)
If you want to go back to the original state, you can either delete the pushurl
entry from .git/config
, or use set-url --delete --push
:
git remote set-url --delete --push origin [email protected]:gitusername/repository.git
After this, calling set-url
without --push
should go back to changing both push and fetch URLs.
It's the name of the remote, eg. origin
The names are also visible when listing the remotes, so you could check your current name (probably also origin
)
git remote -v
origin https://github.com/schacon/ticgit (fetch)
origin https://github.com/schacon/ticgit (push)
And useful when using multiple remotes, e.g. the if you fork a GitHub repo, then you could have a remote to your fork online and the original repo (sometimes called "upstream" by convention)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With