Git and dotfiles
Git
# new branch and merge
git branch new-branch
git checkout new-branch
## new code
git add .
git commit -m "new code"
git checkout main
git merge new-branch
git rebase # re-base to another branch
## show
git show
git log
# delete merged branch
git branch -d new-branch # locally
git push origin --delete new-branch
# git tag
git tag # list tags
git tag -a v1.0 -m "version 1.0"
git tag -d v1.0
git show v1.0
git push origin --tags # push all tags
git push origin v1.0
# rename remote
# add an existing repo to git
git remote add origin git@github.com:user/new-name.git
git remote -v
git add .
git commit -m "init commit"
git push --set-upstream origin main
# fork a repo
## clone the forked repo
git clone <forked_repo>
## add upstream as remote
git remote add upstream <original_repo>
git remote -v
## fetch from upstream repo
## store ino upstream/main
git fetech upstream
## checkout to local main
git checkout main
## merge changes
git merge upstream/main
## push to forked repo
git push origin main
dotfiles
Setup
git init --bare $HOME/.dotfiles
alias dot='$(which git) --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
dot remote add origin git@github.com:name/dotfiles.git
echo "alias dot='$(which git) --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'" >> $HOME/.bashrc # or .zshrc
Configuration
dot config status.showUntrackedFiles no
dot remote set-url origin git@github.com:name/dotfiles.git
Usage
dot ls-tree -r branchname #check added files
dot status
# for shared common config
dot switch main
dot add .zshrc
dot commit -m 'add zshrc'
dot push -u origin main
# for machine specific config
dot switch -c branch
dot rebase main # update any changes in main
dot push -f origin branch
dot add .gitconfig
dot commit -m "add gitconfig"
dot push -u origin branch
dot mv file newname # rename
dot rm file # remove a file
dot rm --cached file # remove file but dont delete
-n --dry-run #try
Replication
git clone --separate-git-dir=$HOME/.dotfiles git@github.com:name/dotfiles.git dotfiles-tmp
git clone -b <branchname> <repo-url> # checkout a specific branch
rsync -av --exclude '.git' dotfiles-tmp/ $HOME/
rm --recursive dotfiles-tmp