git

Configuration

.gitconfig

From my .gitconfig

  • Includes typos.

.gitconfig
[color]
  diff = auto
  status = auto
  branch = auto
  ui = true
[alias]
  ci = commit
  cloen = clone
  co = checkout
  chekcout = checkout
  dif = diff
  l = log
  l1 = log -n1 -p
  ll = log -p
  stauts = status

Bash

git config user.name "Aizat Faiz"
git config user.email email@example.com

Version

Include branch in shell.

Pros:

  • You always know which branch is being worked on.

Aliases

From my .bash_profile

.bash_profile
alias ga='git add'
alias gb='git branch'
alias gba='git branch -a'
alias gau='git add -u'
alias gca='git commit --amend --no-edit'
alias gci='git commit'
alias gcm='git commit -m'
alias gco='git checkout'
alias gdc='git diff --cached'
alias gd='git diff'
alias gdd='git diff --name-only HEAD^ | cat'
alias gf='git fetch'
alias gfgsr='git fetch && git svn rebase'
alias gl='git log'
alias gl1='git log -n1'
alias gl1p='git log -n1 -p'
alias gll='git log -p'
alias gp='git pull'
alias gpr='git pull --rebase'
alias grc='git rebase --continue'
alias gs='git status'
alias gsi='git submodule init'
alias gsu='git submodule update'
alias gsr='git svn rebase'
alias gsrgf='git svn rebase && git fetch && git svn rebase'
alias gf='git diff-tree --no-commit-id --name-only -r HEAD'

Commands

git diff --name-only
git log --graph

Compare diff with another branch, good for flattening:

git diff master..branchname
git diff branchname..master
git diff master..HEAD

Display file changes between revisions:

git diff --name-only HEAD^
git diff --name-status branchname..develop
git diff --name-only branchname..develop
git diff --name-only HEAD^ | xargs mvim -p # useful for opening in multiple tabs
git diff --name-only --diff-filter=d HEAD^ | xargs mvim -p # Filter to ignore deleted files

Which tags include a particular commit:

git tag --contains 741326a842e8c3d443c2787980f2fe6e079ccb39

Delete remote branch

git push origin :dotfiles

Before Pushing

Squash branches as much as possible

git rebase -i master..

Best Practices

Cons

  • No equivalent of hg copy

--fixup

GitHub

See GitHub

GitLab

  • Alot more tools.

    • Time Tracking, Milestones, Weight

Pros

  • Merge Requests

    • You can work on the commit message before merginging.

Cons

  • UI is sparse

Vim

Install vim-fugitive

Inside vim:

In command mode, will open a browser pointing to the file in GitHub

:Gbrowse

This works when lines are highlighted as well.

Resources

Browsers

IDEs

Last updated