Cheatsheet

List config

git config --list

Init global config

git config --global user.name "AaronYang"
git config --global user.email aaron19940628@gmail.com
git config --global user.email byang628@alumni.usc.edu
git config --global pager.branch false
git config --global pull.ff only
git --no-pager diff

change user and email (locally)

# git config user.name ""
# git config user.email ""
git config user.name "AaronYang"
git config user.email byang628@alumni.usc.edu

list all remote repo

git remote -v
modify remote repo
git remote set-url origin git@github.com:<$user>/<$repo>.git
# git remote set-url origin http://xxxxxxxxxxx.git
add a new remote repo
git remote add dev https://xxxxxxxxxxx.git

Clone specific branch

git clone -b slurm-23.02 --single-branch --depth=1 https://github.com/SchedMD/slurm.git

Get specific file from remote

git archive --remote=git@github.com:<$user>/<$repo>.git <$branch>:<$source_file_path> -o <$target_source_path>
for example
git archive --remote=git@github.com:AaronYang2333/LOL_Overlay_Assistant_Tool.git master:paper/2003.11755.pdf -o a.pdf

Update submodule

git submodule add –depth 1 https://github.com/xxx/xxxx a/b/c

git submodule update --init --recursive

Save credential

login first and then execute this

git config --global credential.helper store

Delete Branch

  • Deleting a remote branch
    git push origin --delete <branch>  # Git version 1.7.0 or newer
    git push origin -d <branch>        # Shorter version (Git 1.7.0 or newer)
    git push origin :<branch>          # Git versions older than 1.7.0
  • Deleting a local branch
    git branch --delete <branch>
    git branch -d <branch> # Shorter version
    git branch -D <branch> # Force-delete un-merged branches

Prune remote branches

git remote prune origin