0

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?

Ahmad Ismail
  • 11,636
  • 6
  • 52
  • 87

1 Answers1

0

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!

Casper Dijkstra
  • 1,615
  • 10
  • 37
  • Uhu! It is a bare repo. My bare repo is located in `/media/blueray/WDPurple/_DataBackup/_Work/_DailyBackups/dotfilesBackup`. And it tracks my `$HOME` directory. – Ahmad Ismail Oct 18 '20 at 22:09
  • You can find more details about the question in https://www.reddit.com/r/git/comments/jdl11c/can_not_use_some_of_my_aliases_with_bare_repo/ – Ahmad Ismail Oct 18 '20 at 22:10
  • So what happens when yiu replace it by `media/blueray/WDPurple/_DataBackup/_Work/_DailyBackups/dotfilesBackup/.git`? – Casper Dijkstra Oct 18 '20 at 22:34
  • @blueray I have updated the answer. Please let me know if this works for you and answer the question as resolved if this helped you :) – Casper Dijkstra Oct 20 '20 at 17:44
  • Check `dotfiles config --local status.showUntrackedFiles no` on the article you have referred. It solves the problem of "I didn't set --work-tree=$HOME because I would get too many files, but it would work." It actually does not work. – Ahmad Ismail Oct 20 '20 at 20:22
  • Ah thanks, i thought i misconfigured something :) what i meant was that the combination of aliases didn't throw an error – Casper Dijkstra Oct 20 '20 at 20:35