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 https://github.com/ArtifexSoftware/thirdparty-openjpeg.git 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
remember credentials on wsl in windows
To remember login / password for HTTPS repositories on github, add this ~/.netrc :
machine github.com login <your-github-account> password <your-github-token>
Then chmod 0600 ~/.netrc
Tagging
  • 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 https://github.com/lxn/walk.git
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 https://github.com/lxn/win.git
git fetch lxn-win
To apply his commits: git cherry-pick <sha1>
Synced to:
list local stale branches
#!/bin/bash

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)')
do
  if [ x$(git merge-base master "$r") = x$(git rev-parse --verify "$r") ]
  then
    if [ "$r" != "master" ]
    then
      echo "git branch -d $r"
    fi
  fi
done
remove files from history
brew install bfg
bfg --delete-files <file_name_to_delete>
tips
https://github.com/AGWA/git-crypt - selectively encrypt files in git repo, has brew package, has a windows build in https://github.com/ccleaud/git-crypt

Rename a branch locally and remotely: (from https://gist.github.com/lttlrck/9628955)
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
notes
http://justinhileman.info/article/git-pretty/

Dmitri's script to list status of local vs. remote branches:
# Local branches vs. local master Behind/Ahead
goe --quiet 'github.com/shurcooL/go/exp/12' '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 'github.com/shurcooL/go/exp/12' 'd := LookupDirectory("."); d.Update(); d.Repo.VcsLocal.Update(); fmt.Print(u6.BranchesRemote(d.Repo))' | markdownfmt

Pre-requistes:
go get -u github.com/shurcooL/{goe,markdownfmt,go}

Contributing to someone else's Go project: https://blog.splice.com/contributing-open-source-git-repositories-go/

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

git commit --amend -m "new commit message"
rebasing
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
links
 
Go to index of articles.

Feedback about page:

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

Share on