Finding out the name of the original repository you cloned from in Git

前端 未结 8 1076
予麋鹿
予麋鹿 2021-01-30 01:51

When you do your first clone using the syntax

git clone username@server:gitRepo.git

Is it possible using your local repository to find the name

8条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-30 02:37

    I stumbled on this question trying to get the organization/repo string from a git host like github or gitlab.

    This is working for me:

    git config --get remote.origin.url | sed -e 's/^git@.*:\([[:graph:]]*\).git/\1/'
    

    It uses sed to replace the output of the git config command with just the organization and repo name.

    Something like github/scientist would be matched by the character class [[:graph:]] in the regular expression.

    The \1 tells sed to replace everything with just the matched characters.

提交回复
热议问题