What is GitHub?¶
Sam's homelab repository currently lives on a small Git server in the house. It works, but the server has to be maintained and backed up, nobody outside the home network can reach it, and the only way to discuss a change is to talk about it. GitHub solves these problems: it hosts Git repositories online and adds the tools to collaborate on them.
GitHub in one sentence¶
GitHub is a cloud-based hosting service for Git repositories, with collaboration features built around them.
- Cloud-based: GitHub runs on servers on the internet, and provides its resources on demand. Your repositories are stored there, and are reachable from any computer with a browser or Git.
- Hosting service for Git repositories: the repository on GitHub is a remote, exactly like
/srv/git/homelab.gitin Intermediate Git. You clone it, pull from it, and push to it with the same commands. - Collaboration features: issues, pull requests, code review, permissions, and many more, through a web interface.
Other services do the same job, with their own features: GitLab, Bitbucket, or self-hosted ones such as Gitea and Forgejo. The Git part is identical everywhere; only the collaboration features differ.
Git vs GitHub¶
The two names are often confused, but they are different things:
| Git | GitHub | |
|---|---|---|
| What it is | Version control software | An online service that hosts Git repositories |
| Where it runs | On your computer | On GitHub's servers, used through a browser, Git, or apps |
| Made by | An open source project (started by Linus Torvalds in 2005) | A company (owned by Microsoft since 2018) |
| Works without the other? | Yes: Git works fully offline, or with any other server | No: every GitHub repository is a Git repository |
| Main job | Record the history of files: commits, branches, merges | Store repositories, and add collaboration around them |
flowchart TB
subgraph gh["GitHub (online service)"]
direction LR
repo[("Git repository<br/>sam-rivera/homelab")]
collab["Collaboration features<br/>issues, pull requests, reviews,<br/>permissions, Actions..."]
collab --- repo
end
subgraph pc["Your computer"]
git["Git<br/>local repository"]
end
git <-- "git clone / pull / push" --> repo
browser["Browser"] -- "github.com" --> collab
In short: Git does version control; GitHub hosts the result and makes it easier to manage projects and work together.
What GitHub is used for¶
| Use | What it means |
|---|---|
| Storing projects | Every repository is kept online, with its full history: a backup that is reachable from anywhere |
| Tracking projects and files | Browse files, history, and differences between versions in the browser |
| Collaborating | Several people work on the same files, propose changes through pull requests, and review each other's work |
| Planning work | Issues and projects track tasks, bugs, and ideas |
| Social coding | Profiles, followers, stars: people follow projects and developers they find interesting |
| Open source | Public repositories can be read, copied, and improved by anyone; most open source projects live on GitHub |
Many GitHub features go beyond Git itself: GitHub Actions (automation), GitHub Pages (websites), Codespaces (development environments in the browser), GitHub Copilot (AI assistance). They are all built around repositories.
Accounts and repositories¶
Everything on GitHub belongs to an account:
| Account type | Example | Purpose |
|---|---|---|
| Personal account | sam-rivera |
One person. Owns their own repositories |
| Organization | homelab-club |
A shared account for a team or a company. Owned by people, who manage members and teams |
A repository is identified by its owner and its name: sam-rivera/homelab. That pair also gives its address: https://github.com/sam-rivera/homelab.
The repository page¶
The main page of a repository is organized in tabs, with the files of the default branch displayed under Code:
| Area | Content |
|---|---|
| Owner / name and badge | sam-rivera / homelab, with a Public or Private badge |
| Watch, Fork, Star | Follow notifications, copy the repository to your account, bookmark it |
| Code tab | The files, the branch selector, the number of branches and tags, and the latest commit |
| Latest commit line | Author, message, short hash, date, and a link to the full history (N commits) |
| File list | Each file and folder, with the message and date of the last commit that changed it |
README.md |
Displayed (rendered) below the file list |
| About | Description, website, topics, and links to the README and the license |
| Issues | Tasks, bugs, and discussions about the project |
| Pull requests | Proposed changes, waiting for review and merge |
| Actions | Automated workflows (tests, builds, deployments) |
| Projects | Planning boards and tables |
| Wiki | Documentation pages, separate from the code |
| Security | Security policy, alerts, and advisories |
| Insights | Statistics: contributors, commit activity, traffic |
| Settings | Repository configuration. Only visible to people with admin access |
Most tabs map to a topic of this part: the Code tab is covered on the next pages, Settings on the access and branch pages, and Issues and Pull requests in the collaboration pages.
The Code button (green) gives the URLs to clone the repository, or a ZIP download of its files: see Cloning and forking.
Reading a repository from the browser¶
Many things that need a command with Git are a click away on GitHub:
| To see... | With Git | On GitHub |
|---|---|---|
| The commit history | git log |
N commits link, above the file list |
| One commit | git show <hash> |
Click a commit message or hash |
| The branches | git branch -a |
Branch selector, or N branches link |
| The content of a file | cat file |
Click the file |
| Who changed each line | git blame file |
Blame button on a file |
| The history of one file | git log file |
History button on a file |
Hands-on labs¶
Three labs, from guided to more autonomous. These labs need a browser; Labs 1 and 2 also use the terminal. Read every page and output before moving on: the goal is to build reflexes, not to reach the end.
Lab 1: read a repository, in the browser and with Git¶
Objective: find the key information of a repository on its GitHub page, then check that Git shows exactly the same history.
Prerequisites and initial state: a browser, Git installed, internet access. No GitHub account needed: the repository is public. It is a tiny demonstration repository maintained by GitHub, octocat/Hello-World.
Setup:
mkdir -p ~/git-practice/github-intro && cd ~/git-practice/github-intro
Tasks:
- Open github.com/octocat/Hello-World. Note: the owner, the visibility badge, the name of the default branch shown in the branch selector, the number of branches, and the number of commits.
- Note the message and the short hash of the latest commit.
- Click the N commits link, and look at the full history.
- In the terminal, clone the repository into
~/git-practice/github-intro. - With Git, list all branches (local and remote), and display the history on one line per commit. Compare with your notes.
Expected result and verification:
- Owner
octocat, badge Public, default branchmaster, 3 branches, 3 commits. - The latest commit is
7fd1a60Merge pull request #6 from Spaceghost/patch-1. - With Git,
git branch -ashowsmasterand the three remote branchesorigin/master,origin/octocat-patch-1,origin/test;git log --onelineshows the same 3 commits as the website, with the same hashes.
Solution
# 4. Clone the public repository: no account or password needed
cd ~/git-practice/github-intro
git clone https://github.com/octocat/Hello-World.git
cd Hello-World
# 5. Same information as the web page
git branch -a
git log --oneline
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/octocat-patch-1
remotes/origin/test
$ git log --oneline
7fd1a60 Merge pull request #6 from Spaceghost/patch-1
7629413 New line at end of file. --Signed off by Spaceghost
553c207 first commit
- The website and Git show the same commits with the same hashes: GitHub only displays the Git repository it hosts.
- This repository is older than the switch of GitHub's default branch name to
main, so its default branch is stillmaster. - The latest commit was created by GitHub when a pull request was merged: GitHub features leave ordinary Git commits behind.
Keep the clone for Lab 2, or clean up: rm -rf ~/git-practice/github-intro.
Lab 2: what needs GitHub, and what does not?¶
Objective: separate what Git does on its own from what GitHub adds, by proving the Git part works without any network.
Prerequisites and initial state: Git installed. The setup creates a local repository in ~/git-practice/offline, without any remote.
Setup:
mkdir -p ~/git-practice/offline && cd ~/git-practice/offline
git init -q -b main
git config user.name "Sam Rivera"
git config user.email "[email protected]"
printf 'hostname,ip,role\npi-dns,192.168.1.10,dns\n' > inventory.csv
git add inventory.csv && git commit -q -m "Create inventory"
Tasks:
- Sort the following actions into Git (works offline, on your computer) and GitHub (needs the online service): create a commit; open an issue; create a branch; review a pull request; merge two branches; give a friend write access; view the history; star a repository; revert a commit; fork a repository.
- Disconnect from the network if you can (or simply make sure the repository has no remote with
git remote -v). Then, in~/git-practice/offline, prove your Git column: create a branchnas, addnas,192.168.1.20,storage, commit, merge it intomain, and view the history.
Expected result and verification:
- Git: create a commit, create a branch, merge two branches, view the history, revert a commit.
- GitHub: open an issue, review a pull request, give a friend write access, star a repository, fork a repository.
git remote -vprints nothing, yet every Git action of task 2 succeeds: the merge is a fast-forward, andgit log --onelineshowsAdd NASaboveCreate inventory.
Solution
cd ~/git-practice/offline
git remote -v # nothing: no remote at all
git switch -c nas
echo "nas,192.168.1.20,storage" >> inventory.csv
git commit -am "Add NAS"
git switch main
git merge nas # Fast-forward
git log --oneline
- Git is complete on its own: history, branches, and merges are all local.
- Merging is a Git feature; a pull request is a GitHub feature that proposes, discusses, and then performs a merge.
- Forking is a GitHub concept: Git only knows clones. A fork is a server-side copy of a repository, under another account (see Cloning and forking).
Clean up when you are done: rm -rf ~/git-practice/offline.
Lab 3: get your account ready¶
Objective: prepare the GitHub account used in the rest of this part, as Sam would before moving the homelab to GitHub.
Prerequisites and initial state: a GitHub account (create one at github.com/signup if needed). No setup.
Tasks:
- Sign in, and open your profile page (avatar, top right > Your profile). Note your username: it appears in the URL
https://github.com/<username>. - Make sure two-factor authentication (2FA) is enabled: avatar > Settings > Password and authentication. GitHub requires it for accounts that contribute code. Save the recovery codes somewhere safe.
- In Settings > Emails, find your private
noreplyaddress (it ends with@users.noreply.github.com), and check whether Keep my email addresses private is enabled. - In Settings > Repositories, check the default branch name for new repositories.
- On your profile, open the Repositories tab: it is the list the next labs fill with practice repositories, and empty again.
Expected result and verification:
- You know your username, and 2FA is enabled (the Password and authentication page shows it as enabled, with at least one method configured).
- You have noted your
noreplyaddress, of the form[email protected]. - The default branch name for new repositories is
main(unless you changed it).
Solution
- Why 2FA: anyone who gets your password could push to your repositories or delete them. With 2FA, they also need your phone, authenticator app, or passkey. A passkey can even replace the password and 2FA together.
- Why the noreply address: every commit contains an email address, and commits in public repositories are public. If you want to keep your real address private, configure Git with the noreply address:
git config user.email "[email protected]"(with your own ID and username). With Block command line pushes that expose my email enabled, GitHub even refuses pushes of commits that contain your private address. - Default branch:
mainis GitHub's default since October 2020. It only applies to new repositories created on GitHub; local repositories created withgit initfollow your Git configuration (init.defaultBranch).
Nothing to clean up.