Part 1 of 4

First steps

From nothing installed to your first pushed commit. Budget about twenty minutes, most of which is a one-time setup you'll never repeat on this machine.

1 ยท Create your account

Sign up at github.com/signup. Two decisions are worth thirty seconds of thought:

  • Your username is public and semi-permanent. It appears in every repository URL you own and in every commit you're credited for. Pick something you'd be comfortable putting on a CV โ€” plenty of people regret xX_dragonslayer_Xx.
  • Turn on two-factor authentication immediately. GitHub requires it for most accounts now anyway. An authenticator app is the sensible choice; save the recovery codes somewhere that isn't your laptop.

About your email Every commit records an email address, and if your repo is public, that address is public too. If you'd rather it weren't, GitHub can give you a no-reply address: Settings โ†’ Emails โ†’ Keep my email addresses private. Use the โ€ฆ@users.noreply.github.com address it shows you in step 2 below.

2 ยท Install and configure Git

Git is separate software from your GitHub account. Check whether you already have it:

any terminal
$ git --version
git version 2.45.2

If that prints a version, you're done โ€” skip to the configuration below. If it says command not found:

PlatformHow to install
macOSRun git --version and accept the prompt to install the developer tools. Or, if you use Homebrew: brew install git.
WindowsDownload from git-scm.com. Accept the defaults. This also installs Git Bash, a terminal where all the commands on this site work exactly as written.
Linuxsudo apt install git on Debian/Ubuntu, sudo dnf install git on Fedora.

Tell Git who you are

Git stamps every commit with a name and email. Set them once, globally, before you do anything else โ€” otherwise your first commits will be attributed to nobody, and fixing that after the fact is a nuisance.

one-time setup
$ git config --global user.name "Ada Lovelace"
$ git config --global user.email "ada@example.com"

# name new projects' first branch "main" rather than "master"
$ git config --global init.defaultBranch main

# check it took
$ git config --global --list

Use the same email as your GitHub account (or the no-reply address from step 1). That's how GitHub connects a commit to your profile. Get it wrong and your commits appear on the site with a blank avatar and no link to you.

3 ยท Connect your machine to GitHub

This is the step tutorials skip, and it's where most people get stuck. Your laptop needs to prove it's allowed to push to your account. Your GitHub password will not work โ€” that's been disabled for Git operations since 2021.

Pick one of these. You only need one, and you only do it once per machine.

SSH key recommended

A cryptographic key pair. Slightly more setup, then it works silently forever with nothing to remember or rotate.

The gh CLI easiest

GitHub's official command line tool handles authentication for you through a browser login. If you're unsure, use this.

Option A โ€” the gh CLI

Install it from cli.github.com (or brew install gh, winget install GitHub.cli), then:

browser-assisted login
$ gh auth login
? What account do you want to log into?  GitHub.com
? What is your preferred protocol for Git operations?  HTTPS
? Authenticate Git with your GitHub credentials?  Yes
! First copy your one-time code: A1B2-C3D4
โœ“ Logged in as adalovelace

That's it โ€” Git will now authenticate automatically. The tool is useful for plenty more besides; see Level up.

Option B โ€” an SSH key

Generate a key, add it to your agent, then paste the public half into GitHub.

generate and copy your public key
$ ssh-keygen -t ed25519 -C "ada@example.com"
Enter file in which to save the key: โ† press Enter for the default
Enter passphrase: โ† optional but sensible

$ cat ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... ada@example.com

Copy that entire line, then go to GitHub โ†’ Settings โ†’ SSH and GPG keys โ†’ New SSH key and paste it in. Verify it worked:

confirm
$ ssh -T git@github.com
Hi adalovelace! You've successfully authenticated, but GitHub does not
provide shell access.

That "does not provide shell access" line is success, not an error. It's the expected response and it trips up a lot of people.

The file ending in .pub is the one you share. The other file โ€” no extension โ€” is your private key. It never leaves your machine, never gets pasted into a website, and never goes into a repository.

4 ยท Make your first repository

There are two directions you can come at this from, and it's worth knowing both exist because you'll hit each of them in real life.

Two ways to start a repository Route A: create the repo on GitHub first, then clone it to your computer. Route B: you already have a local folder, so you run git init, then connect it to a new empty GitHub repo and push. Route A โ€” starting fresh (easiest, and what we'll do here) New repo on GitHub click "New" on the website git clone Your computer already connected edit, commit git push Route B โ€” you already have a folder of work Existing folder not yet tracked git init Now a Git repo but only on your machine remote add git push
Route A is less error-prone because GitHub sets up the connection between the two copies for you. Route B needs one extra command to introduce your folder to its new home โ€” shown at the bottom of this section.
  1. Create it on GitHub

    Click the + in the top right โ†’ New repository. Name it hello-github. Tick Add a README file โ€” this matters, because a repo with no commits in it behaves slightly differently and confuses beginners. Leave it Public or set it Private, your call.

  2. Copy the clone URL

    On the new repo's page, the green Code button gives you a URL. Choose the tab matching how you authenticated in step 3 โ€” SSH if you made a key, HTTPS if you used gh.

  3. Clone it

    Move to wherever you keep projects, then pull down a copy:

    clone
    $ cd ~/projects
    $ git clone git@github.com:adalovelace/hello-github.git
    Cloning into 'hello-github'...
    remote: Enumerating objects: 3, done.
    Receiving objects: 100% (3/3), done.
    
    $ cd hello-github
    

    You now have a folder that is aware of its counterpart on GitHub. Cloning downloads the entire history, not just the current files โ€” which is why you can browse the whole past of a project on a plane.

Route B: connecting a folder you already have

Create an empty repo on GitHub โ€” this time don't tick "Add a README" โ€” then, inside your existing folder:

adopt an existing folder
$ git init
$ git add .
$ git commit -m "Initial commit"
$ git remote add origin git@github.com:adalovelace/my-project.git
$ git push -u origin main

git remote add origin โ€ฆ is the introduction โ€” it tells your local repo where its remote counterpart lives. origin is just the conventional nickname for it.

Before running git add . on an existing folder, look at what's in it. That command stages everything, and folders that have been sitting on your disk for a while often contain a .env file, an API key, or a 400 MB build directory. Set up a .gitignore first โ€” see below.

5 ยท Your first commit and push

Now the actual loop. Open README.md in any editor and add a line or two about what the project is.

  1. Ask Git what it sees

    git status is the single most useful command in Git. Run it constantly. It tells you where you are, what's changed, and usually what to type next.

    git status
    $ git status
    On branch main
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
            modified:   README.md
    
    no changes added to commit
    
  2. Stage the change

    Staging is you saying "this file belongs in my next snapshot".

    git add
    $ git add README.md
    

    Run git status again and the file has moved to Changes to be committed, in green. Nothing is saved yet โ€” staging is a waiting room.

  3. Commit it

    This is the actual save. The message is not a formality; it's what you or a colleague will read in eighteen months trying to work out why a line exists.

    git commit
    $ git commit -m "Describe the project in the README"
    [main 7c3f1a9] Describe the project in the README
     1 file changed, 3 insertions(+)
    

    7c3f1a9 is the start of the commit's unique ID. You'll use short IDs like that to refer to specific commits later.

  4. Push it to GitHub

    Your commit exists only on your laptop until you do this.

    git push
    $ git push
    Enumerating objects: 5, done.
    To github.com:adalovelace/hello-github.git
       4b2c1e0..7c3f1a9  main -> main
    

    Refresh the repo page in your browser. Your change is there, your message is on it, and your avatar is next to it. That's the entire fundamental cycle โ€” edit โ†’ add โ†’ commit โ†’ push โ€” and everything else in this guide is a variation on it.

Worth doing right now: repeat that loop two or three more times with small edits. Muscle memory here pays for itself immediately, and it's much cheaper to build it on a throwaway repo than on your team's codebase.

6 ยท What belongs in a repo

Three files show up in nearly every project. None are required, all are conventions worth following.

README.md

Rendered automatically on the repo's front page. What is this, who's it for, how do I run it. If you write one thing, write this.

.gitignore

A list of paths Git should pretend don't exist. Secrets, dependencies, build output, OS clutter.

LICENSE

For public repos. Without one, nobody legally has permission to use your code โ€” "it's on GitHub" is not a licence.

Getting .gitignore right early

Create a file called .gitignore at the top of the repo. Each line is a pattern Git will skip:

.gitignore
# secrets โ€” never, ever commit these
.env
*.pem
credentials.json

# dependencies โ€” reinstallable, and enormous
node_modules/
venv/

# build output
dist/
*.log

# OS noise
.DS_Store
Thumbs.db

.gitignore only ignores files Git isn't already tracking. If you've already committed .env, adding it to the ignore list changes nothing โ€” it's in the history now, and pushing it means it's on GitHub. Stop and read the section on leaked secrets before pushing anything else.

GitHub offers ready-made .gitignore templates for most languages when you create a repo, and maintains a collection of them. Start from one rather than writing your own.

7 ยท The browser-only route

You can do a surprising amount without ever opening a terminal. This is a legitimate way to work โ€” plenty of people edit documentation this way for years.

To do thisIn the browser
Create a repo+ menu โ†’ New repository
Add a fileAdd file โ†’ Create new file, type a path and contents
Edit a fileOpen it, click the pencil icon
CommitThe Commit changes box at the bottom of the editor โ€” that box is a commit message
Make a branchIn that same commit box, choose Create a new branch and start a pull request
A full editorPress . on any repo page to open github.dev โ€” VS Code, in a tab, free

The limits you'll eventually hit: you can't run or test anything, and handling a complicated merge conflict in the web editor is unpleasant. But for a typo fix, a README update, or reviewing someone's work, the browser is often genuinely faster than cloning.

If you want a middle path โ€” buttons instead of commands, but running on your own machine so you can test things โ€” GitHub Desktop is free and maps closely to the concepts on this site.

Back to home