Does git have a built-in command for showing the name of the current remote project? Right now I\'m using this:
git remote -v | head -n1 | awk \'{print $2}\' | s
There is no such thing as a project name in Git. You are simply getting the name of the folder the repository is located in remotely. Git has no built-in way of computing this as it has absolutely no use for it.
basename $(git config remote.origin.url |sed "s/\.git$//")
or:
git config remote.origin.url |sed 's#.*\/\(.*\)\.git#\1#'
I would like to point out the same answer @Mike mentioned in the comments to your question, the $GIT_DIR/description
file. Some other software use this for the name of the repository, such as the post-receive-email hook script. (Which actually does sed -ne '1p' "$GIT_DIR/description"
) and thus simply use the first line from that file as the name of the repository.
What you are doing is fine. I would not trust that someone won't change the name in a readme file. Use the URL as you are doing. Decide on a convention so that origin always refers to the central repo where the urls will contain the identity.
The remote url or the folder in which the git repo is kept can be anything as far as Git is concerned. So you do not have a built-in way for checking this. Git cannot identify what the name of the project is. You have to ( or the owner of the project). Usually, this will be in the form of a README or some similar file checked into the repository that gives the name of the project.
Chained head
awk
and sed
calls like this
git remote -v | head -n1 | awk '{print $2}' | sed 's/.*\///' | sed 's/\.git//'
can be combined into one sed
call like this:
git remote -v | sed -rn '1s#.*/(.*)\.git.*#\1#p'