Git and GitHub: From Zero to Your First Pull Request
Set up Git the right way, generate an SSH key, push your first commit, and open a clean pull request on GitHub — all from the command line.
What you'll build / learn
By the end of this tutorial you'll have Git configured with a sane global setup, an SSH key connected to GitHub, a real repository on your machine, and your very first pull request (PR) opened against a branch. No prior Git experience required.
Prerequisites
- A computer running macOS, Linux, or Windows 10/11.
- A free GitHub account — sign up at github.com if you don't have one.
- Git installed. Check with:
git --version
You want 2.30 or newer. If it's missing or old:
| OS | Install command |
|---|---|
| macOS (Homebrew) | brew install git |
| Ubuntu/Debian | sudo apt update && sudo apt install git |
| Windows | Download Git for Windows and use the included Git Bash terminal |
On macOS, running git --version may prompt you to install Xcode Command Line Tools — accept it, or run xcode-select --install.
Step 1 — Configure a sane global gitconfig
Tell Git who you are. Use the same email you'll use on GitHub.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Now set a few quality-of-life defaults:
# Name the first branch "main" in new repos
git config --global init.defaultBranch main
# Keep history linear when you pull instead of creating merge commits
git config --global pull.rebase false
# Use your platform's default editor (change to taste, e.g. "code --wait")
git config --global core.editor "nano"
Verify everything:
git config --global --list
You should see your name, email, and the settings above printed back.
Step 2 — Generate an SSH key
SSH lets you push to GitHub without typing a password every time, and it's more secure than HTTPS passwords. First check for an existing key:
ls -al ~/.ssh
If you see id_ed25519.pub, you can reuse it and skip to Step 3. Otherwise, create one (the modern, recommended algorithm is Ed25519):
ssh-keygen -t ed25519 -C "you@example.com"
Press Enter to accept the default file location. When prompted, set a passphrase (recommended — it encrypts the key on disk).
Start the SSH agent and add your key so the passphrase is cached:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
macOS note: to store the passphrase in Keychain, run
ssh-add --apple-use-keychain ~/.ssh/id_ed25519instead.
Step 3 — Add the public key to GitHub
Copy your public key (the .pub file — never share the private one):
# macOS
pbcopy < ~/.ssh/id_ed25519.pub
# Linux (install xclip if needed)
xclip -sel clip < ~/.ssh/id_ed25519.pub
# Windows (Git Bash)
clip < ~/.ssh/id_ed25519.pub
If none of those work, just print it and copy manually:
cat ~/.ssh/id_ed25519.pub
Then in your browser:
- Go to GitHub → Settings → SSH and GPG keys.
- Click New SSH key.
- Give it a title (e.g. "My Laptop"), leave Key type as Authentication Key, paste the key, and click Add SSH key.
Test the connection:
ssh -T git@github.com
Type yes if asked to trust the host. Success looks like:
Hi yourusername! You've successfully authenticated, but GitHub does not provide shell access.
Step 4 — Create a repository on GitHub
- Click the + in GitHub's top-right corner → New repository.
- Name it
my-first-repo. - Check Add a README file.
- Click Create repository.
Now clone it. On the repo page, click the green Code button, choose the SSH tab, and copy the URL (it starts with git@github.com:):
git clone git@github.com:yourusername/my-first-repo.git
cd my-first-repo
Step 5 — Create a branch
Never commit straight to main when collaborating. Create a feature branch:
git checkout -b add-greeting
This creates the branch and switches to it. Confirm with:
git branch
The * marks your current branch (add-greeting).
Step 6 — Make a change and commit
Create a small file:
echo "Hello, Git!" > greeting.txt
See what Git noticed:
git status
Stage the file, then commit it with a clear message:
git add greeting.txt
git commit -m "Add greeting file"
A good commit message is short, in the imperative mood ("Add", not "Added"), and describes what the change does.
Step 7 — Push your branch
Send the branch to GitHub. The first push needs -u to link your local branch to a remote one:
git push -u origin add-greeting
Future pushes on this branch are just git push.
Step 8 — Open the pull request
After pushing, GitHub usually shows a yellow banner: "Compare & pull request."
- Click it. (Or go to the repo, open the Pull requests tab, and click New pull request.)
- Confirm the base branch is
mainand the compare branch isadd-greeting. - Add a title and a short description of your change.
- Click Create pull request.
Since you own this repo, you can now click Merge pull request → Confirm merge to merge it into main. 🎉
Verify it works
ssh -T git@github.comreturns the "successfully authenticated" message.git log --onelineshows your commit:
git log --oneline
a1b2c3d Add greeting file
- On GitHub, after merging, switch to the
mainbranch and confirmgreeting.txtis there.
Troubleshooting
git@github.com: Permission denied (publickey).
Your key isn't loaded or wasn't added to GitHub. Run ssh-add ~/.ssh/id_ed25519, then re-test with ssh -T git@github.com. Double-check you pasted the .pub file into GitHub.
fatal: not a git repository
You're not inside the project folder. Run cd my-first-repo first. Confirm with ls -a that a .git directory exists.
Author identity unknown on commit
Git doesn't know who you are. Re-run the two git config --global user.name/user.email commands from Step 1.
Cloned with HTTPS by mistake and keep getting password prompts
Switch the remote to SSH: git remote set-url origin git@github.com:yourusername/my-first-repo.git.
Next steps
- Learn
git pull,git fetch, and how to resolve merge conflicts. - Practice the full collaborator flow by forking someone else's repo and opening a PR against it.
- Read the free Pro Git book and GitHub's official docs.
- Try a graphical client like GitHub Desktop once you're comfortable with the command line.
Discussion 1
Join the discussion
Sign in with GitHub to comment and vote.
i'm still not sure why people overcomplicate git, just use the command line and you're golden, also why not just use the git version that comes with your os, updating to 2.30 or newer isn't necessary for most use cases 🙄