Introduction to Git and GitHub
6 learning objectives Β· 11 key terms Β· 6 commands Β· 3 diagrams Β· 5 quiz questions
Introduction to Git and GitHub
FoundationsWhat you'll be able to do
- Explain what version control is and the problem it solves
- Describe what Git is, what GitHub is, and how they differ
- Compare centralized and distributed version control
- Install Git and prove the install worked
- Create a GitHub account and configure your Git identity
- Name the four places a change lives: working directory, staging area, local repository, remote repository
The idea, in plain language
Version control is a project's memory. Every time you reach a state worth keeping, you record a snapshot with a message explaining why. From that point on you can see who changed what and when, compare any two snapshots, undo a bad change without losing the good work around it, and let several people edit the same project at once without emailing zip files around. Without version control, "the final version (2) REAL final.zip" is the whole strategy β and one overwritten file can cost a week.
Git is a distributed version control system. It was written in 2005 by Linus Torvalds to manage the Linux kernel, after the tool the kernel team had been using stopped being free to use. The key word is distributed: the entire history of a project is copied to your machine when you clone it, so you can commit, branch, compare and inspect history while completely offline. Git needs no server to work β a laptop with one repository is a complete, fully functional setup.
GitHub is a website that hosts Git repositories and adds collaboration on top. It gives your repository a permanent home with a web address, and layers on the things teams need: pull requests for reviewing work before it lands, issues for tracking tasks, Actions for running automated tests, permissions, releases and more. The short version: Git is the tool that records history, GitHub is the place where teams share that history. You can use Git without GitHub, and you can never use GitHub without Git underneath it.
Key terms
- Version control
- A system that records snapshots of a project over time so any earlier state can be inspected or restored.
- Repository (repo)
- A project tracked by Git β a folder plus the hidden .git directory that holds its entire history.
- Commit
- One saved snapshot, with an author, timestamp and message. The unit of history in Git.
- Git
- The distributed version control program that runs on your machine.
- GitHub
- A cloud platform that hosts Git repositories and adds collaboration features such as pull requests and issues.
- Remote
- A named copy of the repository on another machine β usually a GitHub repository β that you push to and pull from.
- Working directory
- The files you are actually editing right now, as they appear in your editor.
- Staging area
- The holding list of changes you have chosen to include in the next commit.
- Local repository
- The committed history stored inside the hidden .git folder on your own machine.
- Distributed version control
- Every clone is a complete repository with full history, not a thin client talking to one central server.
- HEAD
- A pointer to the commit you currently have checked out β "where you are" in history.
How it works, step by step
- 1Check whether Git is already installed
Many systems ship with Git, especially macOS and Linux. Ask for its version before installing anything β if you get a version number back, you are done.
check firstbashgit --version - 2Install Git with your platform package manager
Prefer the official package manager over downloading an installer file: it keeps Git updatable and puts the commands on your PATH automatically.
installbash# macOS (Homebrew) brew install git # Windows (winget, in PowerShell) winget install --id Git.Git -e # Ubuntu / Debian sudo apt install git
- 3Verify the install
A version number in reply means the git program is on your PATH and ready to use. No output, or "command not found", means the install or the PATH did not take effect β restart the terminal first.
verifybashgit --version - 4Create your GitHub account
Sign up at github.com with a username you are happy to appear on public contributions, then turn on two-factor authentication straight away. The email you use here is the one your commits should be attributed to.
- 5Tell Git who you are
Git stamps every commit with a name and email. Until you set these, commits can carry a machine-generated placeholder that GitHub cannot match to your account β so the work does not appear on your profile.
identitybashgit config --global user.name "Ada Lovelace" git config --global user.email "ada@example.com"
- 6Choose how you will drive it
The terminal gives you the full command set and matches every tutorial you will read. A GUI (GitHub Desktop, GitKraken, VS Code's Source Control panel) is a friendly viewer for the same history. Learn the terminal first and the GUI becomes optional; learn only the GUI and you will be stuck the first time a rebase goes sideways.
Commands worth memorising
Every block below is copy-ready β use the Copy button, then paste it into your terminal. Expected output is shown underneath so you know what βworkingβ looks like.
git --versiongit version 2.46.0
Confirms Git is installed and tells you which version you have.
git config --global user.name "Ada Lovelace"
Stored once in your global config and used for every commit on this machine.
git config --global user.email "ada@example.com"
Use an email verified on your GitHub account, otherwise commits will not link to your profile.
git config --global init.defaultBranch main
Makes every new repository start on main instead of the old default master β matches GitHub.
git config --global core.autocrlf true
Converts line endings on checkout and commit so Windows and Linux collaborators stop trading CRLF noise.
git config --list
user.name=Ada Lovelace user.email=ada@example.com init.defaultbranch=main
Shows every setting Git will use, merging system, global and repository config.
Workflow diagrams
The same project exists locally and, once you push, on GitHub. The local copy is always the complete repository β GitHub is a shared copy, not the original.
- You edit files in the working directory.
- git commit records a snapshot into the local repository β no internet needed.
- git push copies those commits up to the GitHub remote so others can pull them.
Learn this picture once and most Git confusion disappears: every command you will ever run moves work along one of these arrows.
- git add moves selected changes from the working directory into the staging area.
- git commit turns everything staged into one snapshot in your local repository.
- git push publishes local commits to the GitHub remote.
- git fetch downloads new remote commits without touching your files; git pull does a fetch and then merges or rebases them into your branch.
| Question | Git | GitHub |
|---|---|---|
| What is it? | A version control program installed on your computer | A hosted website and service for Git repositories |
| Runs where? | Locally, with or without internet | In the cloud, reached over the network |
| Created by | Linus Torvalds and the Git community, 2005 | GitHub, Inc. (now part of Microsoft), 2008 |
| Main job | Record and navigate project history | Share that history, review it, automate around it |
| Key features | Commits, branches, merges, rebase, history | Pull requests, issues, Actions, releases, permissions |
| Can you use one without the other? | Yes β Git works entirely offline | No β GitHub stores Git repositories underneath |
They are not two names for one thing, and neither replaces the other.
- Git is the tool; GitHub is the place you share the toolβs output.
- Every pull request, issue and Actions run on GitHub ultimately operates on commits that Git created.
Worked example
A brand-new project on your first day. Nothing here touches GitHub yet β that is the point: Git is already fully useful by itself.
mkdir recipe-book && cd recipe-book git init # Initialized empty Git repository in /home/ada/recipe-book/.git/ printf '# Recipe Book\n\nA tiny project for learning Git.\n' > README.md git status # On branch main # No commits yet # Untracked files: README.md git add README.md git commit -m "Add project README" # [main (root-commit) 4f1c2ab] Add project README # 1 file changed, 3 insertions(+) git log --oneline # 4f1c2ab (HEAD -> main) Add project README
git log shows one commit, and HEAD -> main tells you where you are. GitHub has no idea this project exists.
Where you'll use it
Common mistakes
- Saying "GitHub" when you mean Git (or the reverse) β it makes every later conversation confusing.
- Installing Git but never setting user.name and user.email, so commits are attributed to a machine name GitHub cannot match.
- Setting user.email to a work address that is not verified on the GitHub account, so contributions never show on the profile.
- Assuming you need an internet connection to commit. Git is local; only push and pull need the network.
- Downloading a random installer instead of using your package manager, then fighting a stale Git for months.
- Skipping two-factor authentication on a new GitHub account β account takeovers start here.
Best practices
- Configure Git identity, default branch and line endings immediately after installing, before the first commit.
- Learn the terminal commands first; add a GUI afterwards if you want one.
- Keep Git up to date with your package manager so you get modern defaults and fixes.
- Pick a GitHub username you will still like in five years β it appears on every contribution.
- Turn on two-factor authentication as soon as the account exists.
Hands-on exercise
Stand up a working Git + GitHub environment
Prove the whole toolchain works before you learn any real Git commands.
- Run git --version. If there is no version number, install Git with your package manager and try again.
- Set your name and email: git config --global user.name "Your Name" and git config --global user.email "you@example.com".
- Run git config --list and confirm both values appear, spelled exactly as you typed them.
- Create a free GitHub account, verify the email, and enable two-factor authentication.
- Create an empty folder, run git init inside it, and note which branch name Git reports.
- Write down, in one sentence each, what Git is and what GitHub is β then check your sentences against the Git versus GitHub table in this lesson.
π‘ Hint: If git --version fails after installing on Windows, close and reopen the terminal β PATH changes only apply to new sessions.
Done when: git config --list prints your name and email, and you have a GitHub account with 2FA enabled.
Checkpoint quiz
0 of 5 answered Β· 0 correct
- Multiple choiceQ1
Which statement best describes the relationship between Git and GitHub?
- Command outputQ2
What does this command print on a machine with Git installed?
git --version
- True or falseQ3
True or false: you need an internet connection to create a commit.
- TroubleshootingQ4
You committed work, pushed it, and opened a pull request β but none of the commits show up on your GitHub profile. What is the most likely cause?
- Multiple choiceQ5
Which area holds changes you have selected for the next commit?
Module summary
- Version control gives a project a navigable history instead of a pile of copies.
- Git is a distributed version control tool that works fully offline; every clone holds the complete history.
- GitHub hosts Git repositories and adds collaboration: pull requests, issues, Actions, releases and permissions.
- Four areas hold your work: working directory, staging area, local repository and remote repository.
- git add, git commit and git push move work rightwards through those areas; git fetch and git pull bring it back.
- Configure user.name and user.email before your first commit so GitHub can attribute your work.
Recommended resourcesAffiliate links Β· may earn us a commission
Recommended for learners
Practice what you learned
Put the GitHub course to work: open one of the company-wise repositories and follow the workflow you just learned, branch to release.