can not use some of my aliases with bare repo

限于喜欢 提交于 2021-01-29 14:32:16

问题


I have some aliases like:

add-and-commit = !git add -A && git commit -m
last = !git --no-pager log -1 --oneline
stash-and-reset = !git stash && git reset --hard HEAD

I track my dotfiles with a bare repo.

d = !git --git-dir=/media/blueray/WDPurple/_DataBackup/_Work/_DailyBackups/dotfilesBackup --work-tree=$HOME

Now the problem is that, i can use:

git add-and-commit
git last
git stash-and-reset

But I can not do:

git d add-and-commit
git d last
git d stash-and-reset

Is there any solution for that?


回答1:


The following works for me:

git init --bare $HOME/.dotfiles
touch $HOME/.dotfiles/.test

git config --global alias.ac '!git add -A && git commit -m'
git config --global alias.dot '!git --git-dir=$HOME/.dotfiles/ $HOME/.dotfiles'
git dot ac "Commit message"

The dot command also works in combination with last and stash-and-reset.

git dot last
4c1db03 (HEAD -> master) testtest

P.S. I didn't set --work-tree=$HOME because I would get too many files, but it would work.

Another way to solve your problem is to create a bash alias to track your dotfiles, this can also be used in combination with other git commands and aliases. See for instance this article!



来源:https://stackoverflow.com/questions/64416625/can-not-use-some-of-my-aliases-with-bare-repo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!