How do you get the Git repository's name in some Git repository?

前端 未结 17 1299
囚心锁ツ
囚心锁ツ 2020-12-22 16:18

When you are working in some Git directory, how can you get the Git repository name in some Git repository? Are there any Git commands?

# I did check out bar         


        
17条回答
  •  误落风尘
    2020-12-22 16:56

    Unfortunately, it seems that Git has no such command built in. But you can easily add it yourself with Git aliases and some shell magic.

    As pointed out by this answer, you can use git rev-parse --show-toplevel to show the root of your current Git folder.

    If you want to use this regularly, it's probably more convenient to define it as an alias. For this, used git config alias.root '!echo "$(git rev-parse --show-toplevel)"'. After this, you can use git root to see the root folder of the repository you're currently in.

    If you want to use another subcommand name than root, simply replace the second part of alias.root in the above command with whatever you want.

    For details on aliases in Git, see also the git config man page.

提交回复
热议问题