What is Git and GitHub? Version control for beginners
Learn what version control is, the difference between Git and GitHub, the core concepts (commit, branch, pull request), and the first commands to get started.
Beginner$ git status▍Have you ever saved a file as final_document.docx, then final_document_v2.docx, and, in desperation, final_document_v3_this_time_for_real.docx? That’s version control done by hand. It works until the day you can’t remember which version had that important part.
Version control is a system that keeps the history of changes to your files. Think of save points in a video game: at each important stage, you save. If something goes wrong, you go back to an earlier point without losing everything else. Git is the most widely used version control tool in the world, and GitHub is one of the most popular places to store and share projects built with Git.
Git and GitHub are not the same thing
Git was created by Linus Torvalds in 2005, the same person who created Linux, to manage the kernel’s source code. It is distributed: every person has a full copy of the history on their own computer and can work even without internet access.
GitHub is a hosting platform for Git repositories, owned by Microsoft since 2018. Besides storing code in the cloud, it adds collaboration features such as code review and automation.
| Git | GitHub | |
|---|---|---|
| What it is | A version control tool | An online service that hosts Git repositories |
| Where it runs | On your computer (terminal) | On the web |
| Needs internet? | No | Yes |
| Maintained by | An open source project | A company (Microsoft) |
| Alternatives | Mercurial, SVN (less common today) | GitLab, Bitbucket, Gitea |
An analogy: Git is the camera that takes the photos; GitHub is the online album where you store and share them.
Core concepts (mini glossary)
| Term | What it means |
|---|---|
| Repository (repo) | The project folder, together with its entire history |
| Commit | A save point: a snapshot of changes, with author, date, and message |
| Branch | A parallel line of work, so you can make changes without affecting the main version |
| Merge | Combining the changes from one branch into another |
| Remote | A copy of the repository somewhere else, like GitHub (usually called origin) |
| Clone | Downloading a full remote repository to your computer |
| Push | Sending your commits to the remote |
| Pull | Bringing new commits from the remote to your computer |
| Pull request (PR) | A request to merge your branch into the main one, with room for review and comments |
First steps in the terminal
If the terminal still feels intimidating, read how to use the terminal first. Start by telling Git who you are (this shows up in every commit):
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Now create a project and make your first commit:
mkdir my-project
cd my-project
git init # turns the folder into a Git repository
echo "# My project" > README.md
git status # shows what changed and what's ready to commit
git add README.md # puts the file in the "staging area"
git commit -m "Add initial README"
git log --oneline # lists the history, one commit per line
git add is like putting items in a box before sealing it: you choose what goes into the next commit. git commit seals the box and sticks a label on it (the message).
Working with branches
git switch -c new-feature # creates a branch and switches to it
# ...edit files, then:
git add .
git commit -m "Add contact page"
git switch main # goes back to the main branch
git merge new-feature # merges the changes
Depending on your Git version and configuration, the main branch may be called master instead of main. The command git branch -M main renames the current branch to main.
Connecting to GitHub
Create an empty repository on the GitHub website and connect your local project to it:
git remote add origin https://github.com/your-user/my-project.git
git branch -M main
git push -u origin main
The -u makes Git remember that destination; from then on, git push is enough. To download an existing project, use git clone https://github.com/your-org/project.git.
About authentication: since 2021, GitHub no longer accepts your account password for Git operations over HTTPS. Use one of these options:
- GitHub CLI: install
ghand rungh auth login. It walks you through the process and sets everything up. - SSH key: a key pair (public and private) that identifies your computer. The public key goes to GitHub; the private key never leaves your machine.
- Personal access token: a password generated by GitHub, with limited permissions, used in place of your account password.
The pull request flow
On teams, almost nobody commits directly to main. The most common path is:
- Create a branch for your task.
- Make small commits with good messages.
- Push the branch with
git push -u origin branch-name. - Open a pull request on GitHub.
- Teammates review and comment, and automated tests run (that’s CI, continuous integration).
- Once approved, the PR is merged into
main.
This flow is the foundation of practices like GitOps and of DevOps culture.
.gitignore and secrets
The .gitignore file lists what Git should ignore, such as downloaded dependencies, temporary files, and local settings:
node_modules/
*.log
.env
Never commit passwords, tokens, or keys. Once pushed to GitHub, a secret should be considered leaked, even if you delete the file later, because it stays in the history. Keep secrets in files like .env (ignored by Git) or in secret managers, and if something leaks, rotate the credential right away.
Good commit messages
A good message explains what changed, briefly, in the imperative mood:
- Bad:
fixes,changed some stuff,asdf - Good:
Fix shipping cost calculation,Add email validation to sign-up form
Think of the message as a note to “future you,” who will read the history trying to understand why something changed.
Try it yourself
- Set your name and email with
git config --global - Create a repository with
git initand make three commits with clear messages - Use
git log --onelineto see your history - Create a branch, make a commit on it, and merge it with
git merge - Create a
.gitignorethat ignores.envfiles and check it withgit status - Authenticate with
gh auth loginand push your project to GitHub - Open a pull request (it can be on your own repository) and merge it
Next steps
Commit early, commit often: every save point is a safety net that lets you experiment without fear.