Git – One more chance to fix not-yet-pushed commits

Git has a really cool feature: Interactive rebase. Roughly, it allows you to “rewrite history” of your (not pushed) commits.

It allows you to:

1. Change the order of commits

2. Change commit messages

3. Merge (Squash) commits.

4. Split commits.

Below is a link to an article where you’ll find how to do these:

Show current git branch and its status

We’re going to make our bash prompt show the current git branch, with a color indicating its status (green = clean, red = dirty, yellow = clean but not pushed to remote)

The result should be something like this:

current git branch in prompt

Add the following code to your ~/.bashrc

if [ -x /usr/bin/tput ] && tput setaf 1 >& /dev/null; then
	c_git_clean=$(tput setaf 2)
	c_git_dirty=$(tput setaf 1)
	c_git_semi_dirty=$(tput setaf 3)
	c_reset=$(tput sgr0)

git_prompt ()
	if ! git rev-parse --git-dir > /dev/null 2>&1; then
		return 0

	git_branch=$(git branch 2> /dev/null | sed -n '/^\*/s/^\* //p')
	if git diff HEAD --quiet 2> /dev/null >&2; then

	if git diff $git_branch origin/$git_branch --quiet 2> /dev/null >&2; then
		if [ dirty=0 ]; then

	echo " ($git_color$git_branch${c_reset})"

#the relevant part is $(git_prompt). the following ps will give you a prompt like:
#[username]@hostname [current directory name] (current git branch) $
export PS1='\[\033[0;33m\]\u\[\033[0m\]@\h [\[\033[1;34m\]\W\[\033[0m\]]$(git_prompt) \[\033[0m\] \$ '

My gitconfig

I’ll put it here without explanations, as it is self-explanatory.
Enjoy ;)

	name = Your Username
	email = Your Mail
	token = Your Github token if relevant

	quotepath = false
	excludesfile = /Your/Home/Directory/.gitignore
	editor = mvim -f #your favorite editor

	default = matching

#I use Kaleidoscope for diff. A great tool if you happen to work on a Mac by the way
[difftool "Kaleidoscope"]
	cmd = ksdiff-wrapper git \"$LOCAL\" \"$REMOTE\"

	prompt = false

	tool = Kaleidoscope

	ui = auto

[color "branch"]
	current = yellow reverse
	local = yellow
	remote = green

[color "diff"]
	meta = yellow bold
	frag = magenta bold
	old = red bold
	new = green bold

[color "status"]
	added = yellow
	changed = green
	untracked = cyan

	st = status # 'git st' is now the same as 'git status'. same for the others
	ci = commit
	br = branch
	co = checkout
	df = diff
	dc = diff --cached
	lg = log -p
	lol = log --graph --decorate --pretty=oneline --abbrev-commit
	lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
	ls = ls-files
	ign = ls-files -o -i --exclude-standard #show files ignored by git

Forking Your Own GitHub Project

Forking a project on GitHub is as easy as a button click. Well, unless you’re forking your own project.

Say you have a project called old_project, and you wand to fork it into a new project called new_project.

This is how to do it:

First, open a new repository at GitHub and call it “new_project”.

Now, in your terminal:

git clone new_project

cd new_project

vim .git/config

replace old_project with new_project in the following line:

url =

Save and quit vim (:wq)
Back to your terminal.

git remote add upstream

git push -u origin master