My git cheatsheet

 

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

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

Commit messages

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 either by using pull requests, or by merge without a fast-forward, 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.

git config --global alias.s status
git config --global alias.a add
git config --global alias.c "commit -m"
git config --global alias.ps push
git config --global alias.pl "pull --rebase"

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

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

And remember

git_fire.jpg