A Git startup cheat sheet


A compilation of useful Git commands when starting with a fresh install.

Set user info:

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

Set the proxy:

The good way to configure the proxy for git is by defining the http_proxy, https_proxy and no_proxy environment variables used by curl and similar tools. Git allows to override http_proxy and https_proxy, as explained below, but unfortunately it does not offer the possibility to override the no_proxy variable.

git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
git config --global https.proxy http://proxyuser:proxypwd@proxy.server.com:8080

Unset the proxy:

git config --global --unset http.proxy
git config --global --unset https.proxy

Do a rebase by default when pulling:

git config --global pull.rebase true

This is in order to avoid polluting the history with merge commits when pulling code from remote branches. In case you don’t want to use a rebase, you can still initiate a “fetch” followed by a “merge”. This need can occasionally take place when you’re responsible for the merges of features between remote branches. But even then, you shouldn’t need to do this frequently.

Don’t use fast-forward when merging:

git config --global merge.ff false

When merging feature branches (aka topic branches), you always want to create a merge commit because you want to track the branch where the changes were made in the history. Creating a merge commit allows to roll back a specific feature from the history at a later stage, or to merge the same modifications in another branch; if for example you work with development and production branches.

Do not commit automatically when merging:

git config --global merge.commit false

This gives you a chance to review the result of the merge before the commit is done. It works in conjunction with the non fast-forward option above.

Flag or fix whitespace problems:

git config --global core.whitespace trailing-space,space-before-tab

  • trailing-space warns about whitespaces at the end of a line or at the end of a file.
  • space-before-tab warns when there is a space before a tab used for indentation.

git config --global apply.whitespace fix

This last option is used in order to fix the whitespace problems when applying a patch.

Enable the recording of the conflict resolutions in order to reapply them more easily:

git config --global rerere.enabled true

Rerere is an acronym for reuse recorded resolution.

This entry was posted in Tips and tricks and tagged , . Bookmark the permalink.

2 Responses to A Git startup cheat sheet

  1. Using git flow is a big step forward in branch and release management.

    • nidget says:

      A big step forward, yes. However I personally prefer to use a repository manager (internal or external) that will allow me to work with pull requests or merge requests. Like GitHub, Atlassian Stash or GitLab. See also the post of Scott Chacon about the GitHub flow: http://scottchacon.com/2011/08/31/github-flow.html

      Anyway, a basic rule when using Git with a lot of people, and eventually distant people, working on the same codebase is to define the Git workflow. This is often the most difficult step in the adoption of Git. So thanks Nicolas for highlighting this point.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s