S/Shortutorial
Home / Programming / Git basics
Programming · Tools

Git Basics in 15 Minutes

Git saves snapshots of your project so you can undo mistakes, try ideas safely and work with other people. Here's the core workflow, minus the jargon.

~15 min4 lessonsStaging simulator5-question quiz
01

Snapshots of your project

Git is version control: it keeps a history of your project as a series of snapshots called commits. You can look back at any snapshot, compare them, or return to one.

Git runs on your computer. GitHub (and similar sites like GitLab) store a copy online so you can back it up and share it.

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

# start tracking a folder
cd my-project
git init
02

The everyday cycle: change, add, commit

Files move through three places:

PlaceWhat it meansCommand to move on
Working folderFiles as you're editing themgit add
Staging areaChanges picked for the next snapshotgit commit
HistorySaved snapshots(done)
git status                       # what has changed?
git add index.html               # stage one file (or: git add .  for everything)
git commit -m "Add contact page"  # save the snapshot
git log --oneline                # see the history

Good commit messages say what the change does, in a few words: “Add contact page”, not “stuff” or “update”.

03

Branches: try ideas safely

A branch is a separate line of work. Make one to try a new feature without touching the working version on main.

git switch -c new-header     # create a branch and move to it
# ...edit, add, commit as usual...
git switch main              # go back to main
git merge new-header         # bring the changes across

Merge conflicts happen when two branches changed the same lines. Git marks the clash in the file with <<<<<<< and >>>>>>>; keep the version you want, delete the markers, then add and commit.

04

Sharing on GitHub

git remote add origin https://github.com/you/my-project.git
git push -u origin main      # first time
git push                     # after that
git pull                     # get other people's changes
git clone https://github.com/someone/project.git   # copy a project

Never commit passwords or API keys. Once pushed, assume they're public. Add files like .env to a .gitignore file so Git ignores them.

Try it · staging simulator

Click files to edit them, then stage and commit.

NEXTKeep learning