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

  • 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
    Other:
    git remote -v : list all remote branches
  • 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\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 empty branches from history
    git filter-branch --prune-empty --tag-name-filter cat -- --all
    git push —force
  • 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
  • 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

Feedback about page:

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

Share on        

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