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:

http://git-scm.com/book/en/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages

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)
else
	c_git_clean=
	c_git_dirty=
	c_reset=
	c_git_semi_dirty=
fi

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

	git_branch=$(git branch 2> /dev/null | sed -n '/^\*/s/^\* //p')
	if git diff HEAD --quiet 2> /dev/null >&2; then
		git_color="${c_git_clean}"
		dirty=0
	else
		git_color="${c_git_dirty}"
		dirty=1
	fi

	if git diff $git_branch origin/$git_branch --quiet 2> /dev/null >&2; then
		git_color="$git_color"
	else
		if [ dirty=0 ]; then
			git_color="${c_git_semi_dirty}"
		fi
	fi

	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 ;)

[user]
	name = Your Username
	email = Your Mail
	token = Your Github token if relevant

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

[push]
	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\"

[difftool]
	prompt = false


	tool = Kaleidoscope

[color]
	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

[alias]
	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 git@github.com:USERNAME/old_project.git new_project

cd new_project

vim .git/config

replace old_project with new_project in the following line:

url = git@github.com:USERNAME/old_project

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

git remote add upstream git@github.com:USERNAME/old_project

git push -u origin master

Done.

Source.