eaglebh
eaglebh

Reputation: 21

How can I determine the url of a git server, inside of a git project?

I need only the server part, for example, if my project is on [email protected]:project.git, I want [email protected]

Thanks,

Upvotes: 1

Views: 3078

Answers (2)

jthill
jthill

Reputation: 60605

Given a url, you just parse the url.

Here's how to find the url of one of your own repo's remotes

If you mean you want to find "the" url for your own repo, that won't work. It all depends on whether or not somebody's fired up a server at a particular address; nothing says there can't be multiples -- and you can use 'file:' urls without any server at all.

Upvotes: 1

tessi
tessi

Reputation: 13574

The following bash command gives you the server part for the remote called origin:

echo `git config --get "remote.origin.url"` | sed "s|\([^:]*\):.*|\1|"

If you are not sure if the remote for the current branch is always called origin, you may execute the following to find the remote of the current branch:

git config --get "branch.master.remote"

Upvotes: 3

Related Questions