Git
Official site for this guide. Start here, then follow the cards below.
Free: Git is free and open source.
Visit GitLearn Git from install to pull requests in 8 short guides: setup, commits, branches, pushing to GitHub, teamwork, undoing mistakes, a command reference and learning tools. Each guide has its own colour.
Git is the tool on your computer that records the history of your files. GitHub is a website that stores Git projects online. You set up Git first.
Official site for this guide. Start here, then follow the cards below.
Free: Git is free and open source.
Visit GitWindows: download the installer from git-scm.com and keep the default options. macOS: run git --version in Terminal and accept the prompt to install the developer tools, or use brew install git. Linux: for example sudo apt install git.
Open a terminal (Git Bash on Windows) and run git --version. You should see a version number.
Run git config --global user.name "Your Name" and git config --global user.email "you@example.com". Use the email on your GitHub account. These details are stamped on every commit.
Run git config --global init.defaultBranch main so new repositories start on a branch called main, the same name GitHub uses.
Run git config --list to see what is set. Run git config user.name to check a single value.
GitHub no longer accepts your account password for Git over HTTPS. Use one of: a personal access token (with Git Credential Manager, installed with Git for Windows), the GitHub CLI command gh auth login, or an SSH key.
Run ssh-keygen -t ed25519 -C "you@example.com" and press Enter to accept the defaults. Copy the public key (the .pub file) and add it in GitHub under Settings, SSH and GPG keys, New SSH key. Test it with ssh -T git@github.com.
A repository is a project folder that Git tracks. A commit is a saved snapshot with a message.
Official site for this guide. Start here, then follow the cards below.
Free: Free. Everything here works offline.
Visit Pro Git bookMake a folder, open a terminal inside it, and run git init. Git creates a hidden .git folder where it stores history.
Create a file such as index.html or README.md and write something in it.
Run git status. The new file shows as untracked, which means Git sees it but is not recording it yet.
Run git add index.html to stage one file, or git add . to stage everything changed. Staging means choosing what goes into the next commit.
Run git commit -m "Add homepage". Write short messages that say what changed and why, in the present tense.
Run git log --oneline to see commits, newest first. Each has a short id you can use later.
Edit the file, then run git diff to see changes not yet staged, and git diff --staged to see what is staged.
Create a file named .gitignore and list patterns such as node_modules/ and .env. Never commit passwords, API keys or secrets. Add the ignore rule before the first commit.
A branch is a separate line of work. You can try an idea without touching the working version on main.
Official site for this guide. Start here, then follow the cards below.
Free: Free. Branches are cheap, so use them often.
Visit Learn Git BranchingRun git branch to list branches. The one with a star is the branch you are on. On a new repository that is main.
Run git switch -c add-contact-page. The -c means create. Pick short names that describe the work.
Edit files, then git add . and git commit -m "Add contact page". These commits belong only to this branch.
Run git switch main. Your files change to match main, and the new work is safely stored on the other branch.
While on main, run git merge add-contact-page. If main has not moved, Git simply fast-forwards. Otherwise it creates a merge commit.
If two branches changed the same lines, Git stops and marks the file with <<<<<<<, ======= and >>>>>>>. Edit the file to keep the right version and remove the markers. Then run git add file and git commit to finish the merge. Use git merge --abort to cancel.
Run git branch -d add-contact-page. Git refuses if the work is not merged, which protects you from losing it.
GitHub hosts your repository online so you can back it up, share it, and deploy from it.
Official site for this guide. Start here, then follow the cards below.
Free: GitHub Free: unlimited public and private repositories. Check the pricing page for current limits on other features.
Visit GitHubSign up at github.com with your email and verify it.
Sign upClick the plus menu, New repository. Choose a name and Public or Private. If you already have a local project, do not tick the option to add a README, so the two histories do not clash.
New repositoryCopy the repository URL from GitHub and run git remote add origin URL. Check with git remote -v. Origin is the usual name for your GitHub copy.
Run git push -u origin main. The -u links your local main to the remote main, so later you can run just git push.
Git asks you to authenticate. Use the browser sign-in from Git Credential Manager, a personal access token as the password, or your SSH key if you used an SSH URL.
Refresh the repository page. You should see your files, the latest commit message, and a History link listing every commit.
To copy any repository to your computer, run git clone URL. This also sets origin for you.
Run git pull to download and merge new commits from GitHub. Run git fetch to download them without merging yet.
A pull request asks the project owner to review and merge your branch. It is the normal way to contribute on GitHub.
Official site for this guide. Start here, then follow the cards below.
Free: Pull requests and issues are free on public and private repositories.
Visit GitHub pull request docsOn the repository page click Fork. GitHub makes your own copy under your account. If you can write to the repository, skip the fork.
Run git clone URL, then git switch -c fix-typo. Never work directly on main of someone else's project.
Make changes, commit them, then run git push -u origin fix-typo.
On GitHub click Compare and pull request. Write a clear title, explain what and why, and submit it.
Reviewers can comment on lines. Make fixes on the same branch and push again. The pull request updates by itself.
The owner chooses Merge commit, Squash and merge (one clean commit) or Rebase and merge. After merging you can delete the branch on GitHub.
Run git switch main, git pull, then git branch -d fix-typo. For a fork, add the original as another remote with git remote add upstream URL and pull from it.
Use the Issues tab to list bugs and ideas. Writing Fixes #12 in a pull request description closes issue 12 when the pull request merges.
Git is forgiving if you know which command fits. Be careful with anything that rewrites history after you have pushed.
Official site for this guide. Start here, then follow the cards below.
Free: Free. Nothing here needs a paid plan.
Visit Oh Shit, Git!?!Run git restore file to put the file back to the last commit. This cannot be undone, so check with git diff first.
Run git restore --staged file to remove it from the next commit but keep your edits.
Run git commit --amend -m "New message". Only do this if you have not pushed the commit yet.
Run git reset --soft HEAD~1. The commit disappears, and its changes stay staged.
Run git revert COMMIT_ID. This adds a new commit that cancels the old one, so shared history stays intact. Find the id with git log --oneline.
Run git stash to hide uncommitted changes, switch branches freely, and run git stash pop to bring them back.
Run git reflog to list where HEAD has been. Find the commit you want and run git switch -c rescue COMMIT_ID to get it back.
Revoke or rotate the password or key immediately. Removing it from a later commit is not enough because it stays in history and may already be copied.
The commands you will use every day.
Official site for this guide. Start here, then follow the cards below.
Free: Free.
Visit GitHub Git cheat sheetShow which files changed and which are staged.
Stage all changes in the current folder.
Save a snapshot of the staged changes.
Show a short history of commits.
Show changes that are not staged yet.
List branches.
Create a branch and switch to it.
Merge a branch into the one you are on.
Show the remote URLs, such as origin.
Upload your commits to GitHub.
Download and merge new commits from GitHub.
Copy a repository to your computer.
Graphical apps, command-line helpers and practice sites.
Official site for this guide. Start here, then follow the cards below.
Free: All free to use.
Visit GitHub DocsFree app for working with Git without the command line.
Open GitHub DesktopThe gh command for logging in, cloning, creating pull requests and more from the terminal.
Open GitHub CLIBuilt into Visual Studio Code, with a panel for staging, committing and syncing.
Open VS Code docsShort interactive courses that run inside GitHub repositories.
Open GitHub SkillsVisual puzzles that teach branching and rebasing.
Open Learn Git BranchingThe free official book about Git, from basics to internals.
Read Pro Git