CRLF conversion, line endings
  • checkout Win CRLF, commit Unix LF: core.autocrlf = true
  • checkout as-is, commit Unix LF: core.autocrlf = input
  • checkout as-is, commit as-is: core.autocrlf = false
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
remember credentials on windows
git config --global credential.helper wincred
Can see stored credentials in Credential Manager program, Windows Credentials tab
  • 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
brew install bfg
bfg --delete-files <file_name_to_delete>
tips - selectively encrypt files in git repo, has brew package, has a windows build in

Rename a branch locally and remotely: (from
git branch -m old_branch new_branch         # Rename branch locally
git push origin :old_branch                 # Delete the old branch
git push --set-upstream origin new_branch   # Push the new branch, set local branch to track the new remote

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
Go to index of articles.

Share on