Is there a way to get the git root directory in one command?

前端 未结 22 1343
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 09:57

Mercurial has a way of printing the root directory (that contains .hg) via

hg root

Is there something equivalent in git to get the director

22条回答
  •  攒了一身酷
    2020-11-22 10:35

    To write a simple answer here, so that we can use

    git root
    

    to do the job, simply configure your git by using

    git config --global alias.root "rev-parse --show-toplevel"
    

    and then you might want to add the following to your ~/.bashrc:

    alias cdroot='cd $(git root)'
    

    so that you can just use cdroot to go to the top of your repo.

提交回复
热议问题