Imagine writing an important document and saving copies named report_final.docx, report_final2.docx and report_really_final.docx. Sooner or later you lose track of which one is the right one, and you cannot see what changed between them. Now imagine a team of five people editing the same set of files. Without a system, they overwrite each other's work. Version control solves both problems. It records every change, who made it and why, and lets you go back to any earlier state. Git is the most widely used version control tool in the world, and almost every software job expects you to know the basics.
Git and GitHub are not the same thing
- Git is a program that runs on your own computer. It keeps the history of your project in a hidden folder called
.git. It works without the internet. - GitHub is a website that stores Git projects online. It lets you back them up, share them, collaborate and show your work. Other services, such as GitLab and Bitbucket, do a similar job. The Git commands you learn work with all of them.
- A simple way to remember it: Git is the tool, GitHub is one place to keep what the tool makes, like a camera and a photo-sharing site.
Why it matters for your career
In software, data and testing jobs, teams use Git every day, and employers often look at a candidate's GitHub page. Even outside software, anyone who works with text files, such as writing, configuration or data, can benefit from a history of changes. No tool can promise a job, but being comfortable with Git removes a barrier that stops many beginners, and a tidy GitHub profile can show your projects to employers.
Install Git
- Windows: download Git for Windows from git-scm.com and run the installer. The default answers are fine. It includes Git Bash, a terminal where Git commands work the same as on Mac and Linux. You can also use PowerShell.
- macOS: open Terminal and type
git --version. If Git is missing, macOS offers to install the developer tools. Accept. You can also install a newer Git from git-scm.com. - Linux: use your package manager, for example
sudo apt install giton Ubuntu or Debian.
Check that it works. Open a new terminal window and type the command below. The version number on your computer will be different, and that is fine.
git --version
git version 2.43.0
A very short terminal refresher
Git is used from the terminal, so you need a few commands. pwd shows the folder you are in. ls (or dir in the Windows command prompt) lists files. cd folder moves into a folder, and cd .. goes up one level. mkdir name makes a folder. You do not need more than this for the whole course. If a command does something you did not expect, check which folder you are in first. Most beginner problems are caused by running a command in the wrong folder.
Tell Git who you are
Every change that Git records has an author. Set your name and email once on your computer. Use the same email you plan to use for GitHub, so that your commits are linked to your account. Be aware that this information becomes part of the history, and is visible if you share the project publicly. GitHub offers a private no-reply email address in its settings if you prefer not to show your real one.
git config --global user.name "Asha Verma"
git config --global user.email "asha@example.com"
git config --global init.defaultBranch main
--globalmeans: use these settings for every project on this computer.- The third line makes the first branch of every new project be called
main, which is the name GitHub uses today. - Replace the sample name and email with your own.
- Check your settings at any time with
git config --list.
What you will learn
This course has ten short lessons. First the Git basics on your own computer: the first repository, saving changes, undoing mistakes, branches and merge conflicts. Then GitHub and teamwork: putting your project online, pull requests and good habits. Last come handy tools and how to use GitHub in your job search. To keep it safe and repeatable, we practise with small invented projects. You can follow along with exactly the same commands.
Your task
- Install Git and check
git --version. - Set your name, email and default branch with
git config --global. - Run
git config --listand find your name and email in the output. - Make a folder called
git-practicefor the course and open a terminal in it.
How to check it worked
git --versionprints a version number.git config --global user.nameprints your name.- You can explain in one sentence the difference between Git and GitHub.