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 email@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.
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.