Skip to content

Latest commit

 

History

History
138 lines (104 loc) · 3.38 KB

File metadata and controls

138 lines (104 loc) · 3.38 KB

My Git Configurations

Global git ignore

This is global(default) ignore configuration. Modify repo/.gitignore for repo specific ignores.

Refer to https://github.com/github/gitignore for more to ignore.

backup files

*~
*.swp

Compilation output

*.elc
*.pyc
*.o
*.class

Cache generated by various applications

.Trashes
Thumbs.db

Global git config

[github]
    user = GITHUB_USERNAME

[user]
    name = Your Name
    email = you@email.com

[checkout]
    defaultRemote=origin

[core]
    excludesfile = ~/.gitignore # A global ignore file
    # autocrlf = false
    # filemode = false
    # pager = less -r   # uncomment this line to have "less" wrap long lines when 'git diff'
    # editor = emacsclient -a \"\" -t

[alias]
    st = status
    df = diff
    ds = diff --stat
    dc = diff --cached

    co = checkout
    ci = commit
    amend = commit --amend

    pk = cherry-pick
    rb = rebase
    rst = reset
    last = log -1 HEAD

    lg = log --graph --abbrev-commit --pretty=format:'%C(cyan)%h%C(reset) - %C(green)%s %C(dim white)- %cr (%an)%C(reset) %C(yellow)%d'
    topo = log --graph --simplify-by-decoration --pretty=format:"%d%h" --all

    # http proxy
    hp = config --global http.proxy localhost:8888
    nohp = config --global http.proxy ""

    recent-branches = for-each-ref refs/heads --sort='-committerdate' --format='%(committerdate:iso) %(refname:short)%09 %(authorname)%09 - %(contents:subject)'

[credential]
    helper = cache --timeout=3600

[color]
    ui = auto

[diff]
    wsErrorHighlight = all

[apply]
    whitespace = warn

[diff "gpg"]
    textconv = gpg --no-tty --decrypt

Block pushing certain branches

To avoid accidentally push branches containing sensitive data, we can add a pre-push to the corresponding repositories.

For example, to block myself from pushing my private configuration branches mine/company to GitHub, I tangle (write) the following code snippet into ~/.dotfiles/.git/hooks/pre-push in with file permission o755.

#!/usr/bin/env bash

protected_branches=("mine" "company")

# Read pushed refs from stdin (format: <local_ref> <local_sha> <remote_ref> <remote_sha>)
while read -r local_ref local_sha remote_ref remote_sha; do

    # Extract branch name from local_ref (e.g., refs/heads/company → company)
    branch_name=$(basename "$local_ref" 2>/dev/null)

    # Check if the pushed branch is protected
    for protected in "${protected_branches[@]}"; do
        if [[ "$branch_name" == "$protected" ]]; then
            echo "Pushes to '$protected' are blocked by your pre-push hook." >&1
            exit 1
        fi
    done

done

exit 0

IMPORTANT:

  • Ensure this file’s permission is correct.
  • Manually copy this file to designated directory if you clone the repository to a different place as this hook script itself is not copied over by git clone.