Try Documentalist, my app that offers fast, offline access to 190+ programmer API docs.

CRLF conversion, line endings
  • checkout as-is, commit as-is: core.autocrlf = false
  • checkout Win CRLF, commit Unix LF: core.autocrlf = true
  • checkout as-is, commit Unix LF: core.autocrlf = input
tracking a remote branch
initial setup:
git remote add upstream <repo>
updating my master with upstream master:
git fetch upstream
git checkout master
git merge upstream/master
git remote -v : list all remote branches
remember credentials on windows
git config --global credential.helper wincred
Can see stored credentials in Credential Manager program, Windows Credentials tab
remember credentials on wsl in windows
To remember login / password for HTTPS repositories on github, add this ~/.netrc :
machine login <your-github-account> password <your-github-token>
Then chmod 0600 ~/.netrc
  • git tag v1 : creates local tag v1
  • git push origin v1 : pushes local tag v1 to the server. On GitHub it shows up in tags/releases tab
  • git push origin --tags : pushes all local tags to the server
tracking remote branch on kjk\walk
git remote add lxn-walk
git fetch lxn-walk
To apply his commits: git cherry-pick <sha1>
Synced to:
tracking remote branch on kjk\win
git remote add lxn-win
git fetch lxn-win
To apply his commits: git cherry-pick <sha1>
Synced to:
list local stale branches

set -o nounset
set -o errexit
set -o pipefail

# stale local branch is one that no longer exists on the server

git checkout master
echo ""
echo "Local stale branches and commands to delete them:"
echo ""
for r in $(git for-each-ref refs/heads --format='%(refname:short)')
  if [ x$(git merge-base master "$r") = x$(git rev-parse --verify "$r") ]
    if [ "$r" != "master" ]
      echo "git branch -d $r"
remove files from history
using bfg repo cleaner
brew install bfg
bfg --delete-files <file_name_to_delete>
java -jar bfg.jar --delete-files "*.json" blog.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
using filter-branch
git filter-branch --tree-filter 'find -wholename "notion_cache/*.json" -type f -exec rm -rf {} \; ' -- --all
git filter-branch --prune-empty --tree-filter 'git rm -rf --cached --ignore-unmatch notion_cache/*.json' -- --all
remove empty branches from history
git filter-branch --prune-empty --tag-name-filter cat -- --all
git push —force

Dmitri's script to list status of local vs. remote branches:
# Local branches vs. local master Behind/Ahead
goe --quiet '' 'd := LookupDirectory("."); d.Update(); d.Repo.VcsLocal.Update(); fmt.Print(u6.Branches(d.Repo))' | markdownfmt

# Local vs. Upstream branches behind/ahead
git remote update 2>&1 >/dev/null && goe --quiet '' 'd := LookupDirectory("."); d.Update(); d.Repo.VcsLocal.Update(); fmt.Print(u6.BranchesRemote(d.Repo))' | markdownfmt

go get -u{goe,markdownfmt,go}

Contributing to someone else's Go project:

squashing commits:
git rebase --interactive HEAD~5 : this will open editor with info for last 5 checkins; 

git commit --amend -m "new commit message"
git fetch
git rebase origin/master
# then push with force, e.g. if I was on branch cassandra2
git push --force origin cassandra2

How to rebase interactively:
git rebase --interactive master : rebases current branch based on master
Using submodules
  • git checkout --recursive ... : checkout with submodules
  • git submodule init, git submodule update : if you forgot --recursive flag, you can do this instead
  • git submodule init : initialize submodules
  • git submodule update : update local submodules to what the server says
  • git submodule add ext2/openjpeg
  • git submodule status : check status of submodules
To point submodule to a different version:
  • cd ext2/openjpeg : go to submodule repository pointed by ext2/openjpeg
  • git checkout master : submodules are in detached head state by default so in order to do something you need to switch to master (or whatever) branch
  • git pull : let's say that in the simplest case we want to point to latest version
  • cd ..\.. : back to main repo
  • git status : verify ext2/openjpeg shows as modified
  • git commit -am "update ext2/openjpeg to latest version" : commit the changes

Feedback about page:

Optional: your email if you want me to get back to you:

Need fast, offline access to 190+ programmer API docs? Try my app Documentalist for Windows