Context: I have the origin
remote with a the default url after cloning a repo. Because of some Bitbucket updates it was suggested that our team would centralize the repositories by creating another account with one App password for all the projects that the team handles.
At first, I've decided to add another remote using:
git remote add norigin <new url>
But pushing to two remotes every time would prove to be a hassle. My search for an one push command solution brought me here.
Basically you can edit/add another url to an existing remote, thus I entered:
git remote set-url --add --push origin [email protected]:username/repo2
Tested if the now git push origin <some branch>
command would push to both remote urls. The git log
would then show that norigin
would be behind by a single commit than the origin
, but I thought it's because it's treated still as a another individual remote, then checked each individual repo and it was indeed pushing to both repos, thus I deleted the norigin
remote.
All's good but when I enter git remote -v
it would only show:
origin [email protected]:username/repo (fetch)
origin [email protected]:username/repo2 (push)
When the expected output should be:
origin [email protected]:username/repo (fetch)
origin [email protected]:username/repo (push)
origin [email protected]:username/repo2 (push)
The Question: as the title says and the expected output shown, how do you show all the urls added on a specific remote?
What I've tried:
git remote -v show origin
git remote get-url --push origin
git remote get-url --all origin
but all of them return a single url, and it's either the old or the new url.
CodePudding user response:
It might depend on the version of Git used.
I just tested your command with a Git 2.35.1, and the git remote -v
works as expected:
origin [email protected]:username/repo1 (fetch)
origin [email protected]:username/repo1 (push)
origin [email protected]:username/repo2 (push)
Check if the .git/config includes
[remote "origin"]
url = [email protected]:username/repo1
fetch = refs/heads/*:refs/remotes/origin/*
pushurl = [email protected]:username/repo1
pushurl = [email protected]:username/repo2
CodePudding user response:
To get the expected output:
origin [email protected]:username/repo (fetch)
origin [email protected]:username/repo (push)
origin [email protected]:username/repo2 (push)
All I had to do was to also add the original repo url just like how I added the 2nd one. Used this same command but with the original url (not really a solution as there wasn't really a problem in the beginning, but if you nitpick like me and you just want to see a push
url for the old/original remote then you can use the below command to add it):
git remote set-url --add --push origin [email protected]:username/repo
How I arrived to the "workaround?":
After rereading this I noticed that the instruction was to add the original repo url when it was added after git remote add
. You can see the instruction below (the example use .org and .com urls):
# Create a new remote called "all" with the URL of the primary repo.
git remote add all [email protected]:jigarius/toggl2redmine.git
# Re-register the remote as a push URL.
git remote set-url --add --push all [email protected]:jigarius/toggl2redmine.git
# Add a push URL to a remote. This means that "git push" will also push to this git URL.
git remote set-url --add --push all [email protected]:jigarius/toggl2redmine.git
Another experiment I did yesterday was to delete all push
urls that was added in the origin
repo, and the result was what gave light to this issue.
C:~\app> git remote -v
origin [email protected]:username/repo (fetch)
origin [email protected]:username/repo2 (push)
C:~\app> git remote set-url --delete --push origin [email protected]:username/repo2
C:~\app> git remote -v
origin [email protected]:username/repo (fetch)
origin [email protected]:username/repo (push)
After deleting all push
urls, it added a default url the same as the fetch
url automatically. I don't know the exact behavior, but I just interpreted this as git making the original/old url to be the default push
url that's why it doesn't have to be shown? Anyway feel free to add to any of this. Also having it shown or not, it would still work as expected as long as you added the new repo (i.e. it will be pushing to both the old and new repo).
PS: As @VonC said in his answer this might differ between different git versions.