Is there a git command that returns the current project name?

前端 未结 11 1338
终归单人心
终归单人心 2021-02-01 17:31

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         


        
11条回答
  •  天涯浪人
    2021-02-01 17:56

    The command git remote -v can not be assumed as reliable because your repository can work with more than one remote repositories. For example, your project is your-project and you have added another-project. After the command you are expecting to see the name of your project but you'll see the name of another project:

    $ git remote -v | head -n1
    ABC https://git.team1.ourcompany.com/another-project.git (fetch)
    ABC https://git.team1.ourcompany.com/another-project.git (push)
    origin https://git.ourcompany.com/your-project.git (fetch)
    origin https://git.ourcompany.com/your-project.git (push)
    

    What I could suggest is to check your repository's configuration, for example:

    $ git config --local remote.origin.url
    https://git.ourcompany.com/your-project.git
    

    In the first approach this is the more reliable but doesn't give 100% insurance.

提交回复
热议问题