First-time Git setup: name, email, default branch, SSH or HTTPS
Tell Git who you are, pick sensible defaults, and choose between SSH and HTTPS for GitHub. Includes a small script that applies the settings in one go.
Not checked by a trusted editor yet Last edited Outdated?
What this changes
Writes five settings to your global Git config (~/.gitconfig): user.name, user.email, init.defaultBranch, pull.rebase and push.autoSetupRemote, replacing any earlier values. It only reads ~/.ssh/id_ed25519.pub and creates no key.
How to undo it
Back up first with cp ~/.gitconfig ~/.gitconfig.bak and copy it back to undo. Or remove one value, e.g. git config --global --unset push.autoSetupRemote.
Every commit records an author name and email. If you have not set them, Git either stops with an error or guesses from your computer’s user and host name and prints a warning. Either way, set them once before your first commit.
The settings that matter
git config --global user.name "Ada Lovelace"
git config --global user.email [email protected]
git config --global init.defaultBranch main
git config --global pull.rebase false
git config --global push.autoSetupRemote true
- user.name / user.email: use the email you registered with GitHub (or the private noreply address GitHub offers in your email settings) so commits link to your profile.
- init.defaultBranch main: new repositories start on
maininstead ofmaster, which matches what GitHub uses for new repositories. - pull.rebase false: when your branch and the remote have both moved,
git pullcreates a merge commit instead of stopping with Need to specify how to reconcile divergent branches. Usetrueif your team prefers rebasing. - push.autoSetupRemote true: the first plain
git pushon a new branch creates the matching remote branch and links it, so you can skip-u origin branch-name.
--global writes to the .gitconfig file in your home folder and applies to every repository. Inside one repository you can override a value by leaving out --global, which is handy for a work email on work projects.
git config --global --list
git config --show-origin user.email
git config user.email [email protected]
SSH or HTTPS?
GitHub shows two kinds of clone URLs. They reach the same repository; only the way you log in differs.
- HTTPS (
https://github.com/owner/repo.git): works on almost any network. GitHub does not accept your account password for Git over HTTPS, so you sign in through a credential helper such as Git Credential Manager, throughgh auth loginfrom the GitHub CLI, or with a personal access token. - SSH (
[email protected]:owner/repo.git): you create a key pair once, add the public half to your GitHub account, and Git stops asking for credentials. Some company networks block the SSH port, in which case HTTPS is the easier choice.
Both are fine; pick one and use it consistently. To see which one a repository uses, and to switch it:
git remote -v
git remote set-url origin [email protected]:owner/repo.git
To create an SSH key and check that GitHub accepts it after you have added the .pub file under Settings, SSH and GPG keys:
ssh-keygen -t ed25519 -C "[email protected]"
ssh -T [email protected]
The script
Save it as git-first-setup.sh and run bash git-first-setup.sh "Your Name" [email protected]. It is safe to run again; it simply overwrites the same settings. It never creates an SSH key for you: it prints your public key if one exists, or the command to make one.
#!/usr/bin/env bash
set -euo pipefail
if [ "$#" -ne 2 ]; then
echo "Usage: $0 \"Your Name\" [email protected]" >&2
exit 1
fi
name="$1"
email="$2"
if ! command -v git >/dev/null 2>&1; then
echo "Git is not installed. Install it first, then run this script again." >&2
exit 1
fi
git config --global user.name "$name"
git config --global user.email "$email"
git config --global init.defaultBranch main
git config --global pull.rebase false
git config --global push.autoSetupRemote true
echo "Git is configured:"
git config --global --list | grep -E '^(user\.|init\.|pull\.|push\.)'
key="$HOME/.ssh/id_ed25519.pub"
if [ -f "$key" ]; then
echo
echo "Found an SSH public key. Add it to your Git host if you have not yet:"
cat "$key"
else
echo
echo "No SSH key at $key."
echo "To create one (press Enter to accept the default path, then pick a passphrase):"
echo " ssh-keygen -t ed25519 -C \"$email\""
fi
On Windows, run it from Git Bash, which comes with Git for Windows.
See also
- 0033 The everyday Git workflow: status, add, commit, push, pull Git moves your changes through three places: the working folder, the staging area, and the commit history. These five commands, plus .gitignore… Beginner · Concept · Any system Article Housekeeping · Setup 15 Oct 2026
- 0262 Make your first pull request: Git and GitHub from first commit to merged change A complete beginner's path through Git and GitHub: set up Git, make commits, ignore files, use branches, push to GitHub, open a… Beginner · Tutorial · Any system Article Branching & rebasing · Pull requests · Setup 15 Oct 2026
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Commitpedia +4,002 chars