Skip to content

This guide and website are in beta! Help us make them awesome with your feedback!

Setting up Git's Defaults

Git has a lot of default settings you can change to match your personal preferences. These settings are stored in a configuration (config) file and can be updated at any time using the git config command. Most settings can be updated globally (for all of your repositories) or locally (on a per repository basis).

Git config commands all follow this format:

Terminal window
git config <setting_key> <value> [flags]

You can review individual settings by running:

Terminal window
git config <setting_key>

<setting_key> should be the name of the setting you want to check. For example, to check the name of your global config, you run:

Terminal window
git config --get user.name

To see a list of all your existing configuration values (but not all possible settings), run:

Terminal window
git config -l

If you run this command inside of a repo, you may see fewer or different settings than when you run it outside of one. This is because most defaults are set globally. To see the global configuration while inside of a repo, you can run the command:

Terminal window
git config --global -l

When you commit (save things to Git’s memory), your name and email are associated with the changes in Git’s log. Since Git was primarily designed for teams, this allows teams to keep track of who made changes to the code and when.

Git’s config requires you to enter a name and email address. In fact, if you try to commit without a name and email set, you will receive an error message.

There’s no requirement that the name you enter be your wallet name or that you provide a functional email address. You can use your fandom nickname or even a single unicode character for your name. And although Git does check to ensure the email address provided is a valid format, it doesn’t do any further checks. There are no confirmation emails sent or any further validation required.

When choosing the name and email address to use, we recommend you consider whether you:

  • may at any point share your code publicly on GitHub or similar cloud-based services
  • plan to contribute to open source projects
  • primarily use your machine for professional or personal projects

Remember: you can set your name and email on a per repo basis! This means you can choose the most common (or safer) name for the global configuration, and then override it as needed. For example, if you primarily use Git to build a professional coding portfolio under your wallet name, you can make those values the global setting, then use a local setting for the projects you want associated with your “personal hobby” identity.

Being mindful of how (global versus local) you set your name and email can save you a lot of time, pain, and effort later!

To set your global name and email, copy the commands below, replace our placeholders with the name and email you want to use (but keep the quotation marks!), and run the command in your terminal:

  1. Set your name.

    Terminal window
    git config --global user.name "Boba-tan"
  2. Set your email.

    Terminal window
    git config --global user.email "boba-tan@fujocoded.com"

When Git is first initialized in a repository, it creates a starting branch for you to save your work to. By default, that branch is called “master”. Recently, it’s more common for projects to use “main” for this branch. We recommend you set this as a global configuration.

To make this change, run:

Terminal window
git config --global init.defaultBranch main

Git brings up a text editor for editing commit messages if you fail to add a flag or if you intentionally choose to use one in order to create multiline commit messages. Git may also need a text editor for resolving conflicts that can sometimes arise when pieces of code are edited in ways that it can’t resolve automatically.

If you decide it’s time to change your editor settings, you can run the following command. Note that we’ve provided common options for a text editor for each OS. You can find a full list of editors for this setting on Git’s website.

Terminal window
git config --global core.editor notepad

When collaborating on projects with people who use different operating systems, subtle difference between these systems can often make code harder to review. For example, MacOS and Linux both handle line endings and new lines differently than Windows. This can result in it appearing that a user on a different operating system has touched every single line of code when they submit an update.

Regardless of whether you collaborate with others, we recommend you update this setting since nothing will change for you either visually or with how your system operates.

To automatically align your line endings to the MacOS/Linux standard, run:

Terminal window
git config --global core.autocrlf true

As you progress in your Git journey, you’ll find yourself syncing (pulling) your code changes with the ones on remote, cloud-based Git repositories—either while collaborating with others or for your own personal backup. Git has different ways to manage this process, each with its own pros and cons.

To help avoid accidental changes from using the wrong method, we recommend you update the pull command to “Only ever fast-forward”. This change will force you to make an explicit choice when needed rather than defaulting to a method that might not be desirable.

Although updating this setting will primarily impact your use of GitHub and other remote, cloud-based Git services, we recommend doing so early in your Git journey.

Run the following in your terminal:

Terminal window
git config --global pull.ff only

Git aliases allow you to create your own shorthands for commands (and flags!) you use frequently. This allows you to type less and get the same result, saving you time and effort. Creating a new alias can be useful when you:

  • find yourself typing the same thing over and over
  • need to look up some commands or flags frequently

For example, many Git users (and the FujoGuide team!) recommend reviewing Git’s history with the command git log --all --decorate --oneline --graph to get a more visual and easier-to-read history of changes. However, that’s quite a lot to type and remember, which makes this a good candidate for your first alias.

To create the git adog command alias (adog standing for --all, --decorate, --oneline, and --graph), run the following command in your terminal:

Terminal window
git config --global alias.adog 'log --all --decorate --oneline --graph'

Now, you can simply run git adog to review Git’s history.

We encourage you to make your own aliases with time as you find new favorites.

If you haven’t followed along or want to make sure everything is set up correctly, you can use the following tool to set your git configuration to our suggested settings! Just make sure to change your username and email to your desired values.

Your settings

Choose your Git settings then run the command in your terminal to apply them!

Platform
Terminal window
git config --global user.name "Boba-tan" && `
git config --global user.email "boba-tan@fujocoded.com" && `
git config --global init.defaultBranch main && `
git config --global core.autocrlf true && `
git config --global pull.ff only && `
git config --global alias.adog 'log --all --decorate --oneline --graph'