document.write("
[user] name = user_name email = user_email [apply] # Detect whitespace errors when applying a patch whitespace = fix [core] editor = nvim autocrlf = input safecrlf = true [color] # Use colors in Git commands that are capable of colored output when # outputting to the terminal. (This is the default setting in Git ≥ 1.8.4.) ui = auto [color "branch"] current = yellow reverse local = yellow remote = green [color "diff"] meta = yellow bold frag = magenta bold # line info old = red # deletions new = green # additions [color "status"] added = yellow changed = green untracked = cyan [merge] keepBackup = false tool = p4merge [mergetool] prompt = false [mergetool "p4merge"] cmd = p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED" keepTemporaries = false trustExitCode = false keepBackup = false [diff] tool = p4merge [difftool] prompt = false [difftool "p4merge"] cmd = p4merge "$LOCAL" "$REMOTE" keepTemporaries = false trustExitCode = false keepBackup = false [push] # change to maching for machines with older versions of git 1.x.x default = simple [pull] rebase = true [commit] template = ~/.git-commit-template.txt
# Make sure you're adding under the [alias] block. [alias] st = status s = status -s -b a = add ap = add -p c = commit --verbose ca = commit -a --verbose cm = commit -m cam = commit -a -m m = commit --amend --verbose d = diff ds = diff --staged dch = diff --name-status -r dca = diff --cached co = checkout cob = checkout -b fo = fetch origin po = push origin m = merge mstop = merge --no-commit mff = merge --no-ff mffstop = merge --no-ff --no-commit pi = cherry-pick -x pigo = cherry-pick --continue pistop = cherry-pick -x --no-commit # push all pushitgood = !echo 'Ah, push it' && git push -u origin --all && echo 'P-push it real good' # Undo clashes with git-extras rh = reset --hard unstage = reset HEAD -- # delete merged branch cleanmerged = !git branch --merged | grep -v \\"\\\\*\\" | xargs -n 1 git branch -d # When used without any argument it will print all changes since the last tag (changelog clashes with git-extras) changes = "!f() { r=${1:-`git describe --tags --abbrev=0`..HEAD}; echo Changelog for $r; git log --reverse --no-merges --format='* %s' $r; }; f" ## Logs ## ########## # one-line log l = log --pretty=format:"%C(yellow)%h\\\\ %ad%Cred%d\\\\ %Creset%s%Cblue\\\\ [%cn]" --decorate --date=short hist = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative tree = log --oneline --decorate --graph last = log -1 HEAD new = !sh -c 'git log $1@{1}..$1@{0} "$@"' whois = "!sh -c 'git log -i -1 --pretty=\\"format:%an <%ae>\\n\\" --author=\\"$1\\"' -" whatis = show -s --pretty='tformat:%h (%s, %ad)' --date=short # list branches sorted by last modified b = "!git for-each-ref --sort='-authordate' --format='%(authordate)%09%(objectname:short)%09%(refname)' refs/heads | sed -e 's-refs/heads/--'" # Git Commit, Add all and Push — in one step. cap = "!f() { git add .; git commit -m \\"$@\\"; git push; }; f" # NEW. new = "!f() { git cap \\"📦 NEW: $@\\"; }; f" # IMPROVE. imp = "!f() { git cap \\"👌 IMPROVE: $@\\"; }; f" # FIX. fix = "!f() { git cap \\"🐛 FIX: $@\\"; }; f" # RELEASE. rlz = "!f() { git cap \\"🚀 RELEASE: $@\\"; }; f" # DOC. doc = "!f() { git cap \\"📖 DOC: $@\\"; }; f" # TEST. tst = "!f() { git cap \\"✅ TEST: $@\\"; }; f"
At first, list all local branches:
\n$ git branch\n
\nWe need to know what branches are already merged in “development” and can be easily removed:
\n$ git checkout development\n$ git branch --merged\n
\nNow, remove all outdated branches with:
\n$ git branch -d old-merged-feature\n
\nNext, decide what to do with not merged branches:
\n$ git branch --no-merged\n
\nIf some of them is just abandoned stuff that you don’t need anymore, remove it with “-D” option:
\n$ git branch -D old-abandoned-feature\n
\nAfter each git pull or git fetch command Git creates references to remote branches in local repository, but doesn’t clean up stale references.\nList referenced remote branches:
\n$ git branch -r\n
\nClean-up outdated references:
\n$ git remote prune origin\n
\nUpdate repository with (and Git automatically prunes all stale references):
\n$ git fetch -p\n
\nUsually, remote repository is a big garbage heap of stale branches, if there is no responsible housekeeping person.\nAfter previous git remote prune origin we should have synched list of remote branches.
\nAt first, we can find branches which are already merged in “development””:
\n$ git checkout development\n$ git branch -r --merged\n
\nBut this command does not provide much information. What if this branch is merged, but still used for feature development. Would be cool to know last commit date and author.
\nThis magic snippet provides all required information:
\n$ for branch in `git branch -r --merged | grep -v HEAD`; do echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\\\t$branch; done | sort -r\n
\nNow, you can delete own remote branches, and ask other authors to clean-up theirs:
\n$ git push origin --delete branch-name\n
\nSimilar snippet for not merged branches:
\n$ for branch in `git branch -r --no-merged | grep -v HEAD`; do echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\\\t$branch; done | sort -r\n
\ngit flow init -d\n
\n(Omit -d
if you want to select values other than the defaults.)
This creates a new branch based on develop
and switches to it:
git flow feature start FEATURENAME\n
\nThis merges the feature into develop
, removes the feature branch, and switches to develop
:
git flow feature finish FEATURENAME\n
\nPush a feature branch to remote repository:
\ngit flow feature publish FEATURENAME\n
\nGet a feature published by another user from remote repository:
\ngit flow feature pull origin FEATURENAME\n
\nCreate release branch from develop
:
git flow release start RELEASENAME\n
\nPublish release branch:
\ngit flow release publish RELEASENAME\n
\nCreate a local tracking branch for a remote release:
\ngit flow release track RELEASENAME\n
\nMerge release branch into master
, tag it, merge back into develop
, and remove the release branch:
git flow release finish RELEASENAME\ngit push --tags\n
\nCreate hotfix branch from master
:
git flow hotfix start VERSIONNAME\n
\nCreate hotfix branch from some other commit:
\ngit flow hotfix start VERSIONNAME BASENAME\n
\nMerge hotfix back into develop and master, and tag:
\ngit flow hotfix finish VERSIONNAME
\n
protected_branch='master' current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\\(.*\\),\\1,') if [ $protected_branch = $current_branch ] then read -p "You're about to push master, is that what you intended? [y|n] " -n 1 -r < /dev/tty echo if echo $REPLY | grep -E '^[Yy]$' > /dev/null then exit 0 # push will execute fi exit 1 # push will not execute else exit 0 # push will execute fi