In this demo, you’ll see where Git stores configuration information and how to make a Git repo using the terminal and GitHub Desktop.
To follow along, open Terminal on your Mac and navigate to a place where you’d like to make a new repository.
cd ~/Documents
Let’s first check to ensure your user.name and user.email are correct.
git config --get-regexp user
Because you’re not currently in a Git repository, the only configuration information is from the global configuration file. Because this is a newly-installed Git, there is nothing for Git to show in that file.
Add an entry for user.name. Note that you must put quotes around any text value that contains spaces:
git config user.name "Jim Appleseed"
Typing the config command followed by the name of a key and some value is the same as typing git config --add key value. Similarly, instead of typing git config --get key, you can use this shortened command:
git config user.name
Now, add an email address:
git config user.email "appleseedj@example.com"
Before making a new repository, confirm that the global configuration file looks good by listing the contents:
git config -l
You see your two entries below two of the system entries. credential.helper tells Git to look in your macOS keychain for passwords; don’t store them in configuration files. init.defaultbranch sets the default branch’s name for every new Git repository.
Now, it’s time to make a repository. You can either make the directory first or ask Git to make the directory. Make a directory and then navigate into it.
mkdir myFirstRepo
cd myFirstRepo
You can confirm the directory is empty by listing its contents, including any invisible files.
ls -a
You can also prove Git isn’t monitoring this directory by trying to execute a Git command. For exmaple, you’ll get an error if you ask Git to give you the status.
git status
Because you are in the right directory already, you can use the init command without any arguments:
git init
Git tells you it’s made this directory into a new repository. List the contents of the directory again, including hidden files, and you’ll see there is now a .git directory. You can ask Git for a status now.
git status
Git tells you what branch you’re in and that there’s nothing to commit. Now that you’re in a repository, git config has more entries:
git config -l
To change the user.name for just this repo, you can add an entry to the configuration file:
git config user.name "Jerry Appleseed"
Now, when you list the configuration’s values, you see the global entries, followed by the local entries. If you’re ever confused about where an entry came from, add the --show-scope argument to the list command to make Git tell you.
git config -l --show-scope
Using the terminal, Git won’t complain about a missing user.name and user.email until you try to make a commit. Using this freshly downloaded copy of GitHub Desktop, you’ll see how it approaches the problem. If you’ve already added user.name and user.email, you can just watch; don’t delete the entries.
First, I navigate back to my Documents directory and erase the entries for user.name and user.email from the global configuration.
cd ~/Documents
git config --global --unset user.name
git config --global --unset user.email
Next, launch GitHub Desktop for the first time. Skip the screen about connecting to github.com, and GitHub Desktop asks for a user.name and user.email. Now that it’s asking to connect to a repo, open the one you just made.
In the GitHub Desktop menu under Settings, you can go to the Git section and see the values you just entered. You can also see the “default branch name”. These are global settings. Remember that this repository has a local user.name.
In the Repository menu, open Repository Settings, click Git Config, and see the name you entered.
Earlier in the demo, you saw how to make a new repository using Terminal. With GitHub Desktop, you use the File menu and select New Repository… . Some extra fields here become important once you’re hosting a repository on github.com for people to discover and use. You’ll learn about those in the next lesson. For now, just click Choose... to get a standard macOS file chooser. You can either click New Folder or select a folder.
If you select a folder that Git is already managing, you’ll get this error. You can either select another folder or click the add this repository link to switch to the Add Local Repository… screen.
In the next section, you’ll learn some of the commands you’ll use every day when working with a repository.