Skip to content
Commitpedia
Log in Join & edit

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.

Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?

Edit history of First-time Git setup: name, email, default branch, SSH or HTTPS: 1 recorded edit
Edit history · 1 edit
Type
Script
Edits
1
Editors
1
First issued
15 Oct 2026
Last edit
15 Oct 2026
Language
bash
Licence
CC0-1.0

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 main instead of master, which matches what GitHub uses for new repositories.
  • pull.rebase false: when your branch and the remote have both moved, git pull creates a merge commit instead of stopping with Need to specify how to reconcile divergent branches. Use true if your team prefers rebasing.
  • push.autoSetupRemote true: the first plain git push on 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, through gh auth login from 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.

Did this work for you?

No votes yet. Be the first.

If it did not work, the report form below tells the editors what went wrong.

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 · Explains an idea · 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 · Guided project · Any system Article Branching & rebasing · Pull requests · Setup 15 Oct 2026
  • 0318 Fix: fatal: not a git repository Git looked in the current directory and every parent for a .git folder and found none. You are in the wrong directory,… Beginner · Fixes an error · Any system Article Common errors · Setup 15 Oct 2026
  • 0381 pre-commit hooks: catch mistakes before they are committed Install the pre-commit framework, configure hooks for whitespace, YAML and JSON syntax, large files, leaked private keys, Python linting and shellcheck, run… Beginner · Step by step · Linux, macOS, Windows Article Pipelines, runners & hooks · Setup 15 Oct 2026
  • 0390 Install Git on Linux, macOS and Windows Install Git from your package manager, Xcode's command line tools or the Windows installer, confirm the version, and do the one-time configuration… Beginner · Step by step · Linux, macOS, Windows Article Installing languages & tools · Setup 15 Oct 2026
  • 0422 Dotfiles: keep your shell setup in git Put .bashrc, .zshrc, .gitconfig and your editor settings into a git repository so a new machine is set up in minutes: a… Intermediate · Step by step · Linux, macOS Article Modern command-line tools · 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.

  1. Dominik +4,002 chars

Report a problem

Something wrong, unsafe or copied? Tell the editors.
What is wrong?