Our git guidelines and cheatsheet

When we first started working with Git (moved on from TFS), we tried numerous GUI clients in order to “simplify“ our transition. Well, numerous tries later, the CLI is our best friend.

During the transition process, we found out that there were some semantically different things we had to address in order to improve the semantics of our git history and branch management. Feel free to use them as a “cheatsheet“ of your own.

Commit messages

We agreed that, commit messages should be in a capitalized, imperative, and present simple format - for example, 

Fix controller formatting 

instead of 

fixed controller formatting. 

This convention is based on the messages generated by Git commands, so committing after a “git revert” input yields a consistent message.

We generally follow Chris Beams’s 7 step guide on How to Write a Git Commit Message

Branch management

With git you always want to work in branches. For everything!

First, create a new local branch, branching from the main one (in our case master):

git checkout -b foo master

Now you have a local new branch. To push it to the remote origin, do the following:

git push -u origin foo

After working for a while in your feature branch, the master may diverge with its own commits. To catch up and fix any concurrency issues do the following:

git fetch
git rebase origin/master
git push origin foo

When everything is done and tested, it’s time to merge the feature branch back to master. We do this without a fast-forward merge, for a cleaner git history:

git checkout foo
git fetch
git rebase origin/master

git checkout master
git pull --rebase
git merge --no-ff foo 
git push

To remove remote branch instance:

git push --delete origin foo

To remove local branch as well:

git branch -d foo

Some Alias sugar

We incorporated some aliases in our day-to-day work, that we actually kinda feel crippled without when using someone else’s machine and those aliases aren’t there.

s = status
c = commit -m
ps = push
pl = pull --rebase
a = add

There are some others, but those are the ones we actually can’t live without.

Tell us about your guidelines and most commonly used tools in Git

And remember

git_fire.jpg