Introduction to GitHub¶
Introduction to Git and Intermediate Git used Git on its own, with a small server on the local network as the shared remote. This part moves the project to GitHub: creating and editing repositories in the browser, controlling who can access them, authenticating from the terminal, and collaborating through forks, issues, and pull requests.
Learning path¶
Follow the pages in order: each one builds on the previous one and ends with hands-on labs.
| Topic | Page | Main features and commands |
|---|---|---|
| GitHub basics | What is GitHub? | Git vs GitHub, the repository page |
| Creating a repository | New repository, visibility, README, .gitignore, license |
|
| README files and Markdown | Web editor, Markdown syntax, what a good README contains | |
| Working with repositories | Managing files on GitHub | Create, upload, edit, delete files; commits from the browser |
| Branches and branch protection | Create, switch, compare branches; protection rules | |
| Repository access and collaborators | Public and private repositories, collaborators, roles | |
| Authenticating with personal access tokens | PATs, credential helpers, git push over HTTPS |
|
| Collaboration | Cloning and forking | git clone, forks, upstream, Sync fork |
| Issues | Create, assign, mention, link, close issues | |
| Pull requests | Base and compare branches, opening a pull request | |
| Reviewing and merging pull requests | Reviews, merge methods, deleting and restoring branches |
The big picture¶
GitHub hosts the remote repository and adds collaboration features around it. The typical cycle of a change:
flowchart LR
issue["Issue<br/>describe the task"]
branch["Branch<br/>(or fork)"]
commits["Commits<br/>in the browser or pushed from Git"]
pr["Pull request<br/>propose the change"]
review["Review<br/>comment, approve, request changes"]
merge["Merge into main<br/>issue closed, branch deleted"]
issue --> branch --> commits --> pr --> review --> merge
review -- "changes requested" --> commits
- Describe the work in an issue.
- Create a branch (or a fork, if you cannot write to the repository).
- Commit on it, in the browser or locally followed by
git push. - Open a pull request to propose merging the branch into
main. - Reviewers comment, approve, or request changes.
- The pull request is merged; the issue closes and the branch can be deleted.
The example project¶
The homelab project moves to GitHub as sam-rivera/homelab: the notes and hardware inventory of a few home servers, maintained by Sam Rivera. It keeps its three files, and gains a small Python backup script along the way:
| File | Content |
|---|---|
README.md |
A description of the project, written in Markdown |
inventory.csv |
One line per machine: hostname,ip,role |
services.md |
Which service runs on which machine |
scripts/backup.py |
A backup script for the NAS (added on Managing files on GitHub) |
From the access page onwards, Alex Martin (alex-martin) helps Sam: first as a collaborator, then as an outside contributor working from a fork.
Usernames such as sam-rivera and alex-martin are examples: replace them with your own username in the labs.
Practice environment¶
The labs of this part need:
- A GitHub account. A free account is enough for every lab. Sign up at github.com/signup if you do not have one.
- Git on Linux, as in the previous parts, for the labs that use the terminal. Terminal work happens in
~/git-practice, as before.
The labs create practice repositories named homelab-practice-... in your account. Each lab ends with a cleanup step that deletes them (Settings > General > Danger Zone > Delete this repository), along with any token it created. Never practice on a repository that matters to you.
A second account is not required. When a lab plays two people (Sam and Alex), you play both roles from your own account, and the lab says which steps would normally be done by the other person. If a friend or a second account is available, the role-play labs work even better with two real people.
The GitHub interface changes
GitHub updates its web interface regularly: a button may move or be renamed slightly. These notes give the path to each feature (for example Settings > Collaborators) and its exact label at the time of writing. If a label differs, look for the same feature in the same area of the page. The Git commands and outputs are stable; they come from real sessions with Git 2.55.
Summary¶
GitHub features¶
| Feature | Where | Purpose |
|---|---|---|
| New repository | + > New repository | Create a repository, with optional README, .gitignore, and license |
| Web editor | Pencil icon on a file | Edit a file in the browser and commit it |
| Add file | Code tab | Create a new file or upload files |
| Branch selector | Code tab, above the file list | Switch branches, or create one |
| Branch protection | Settings > Branches (or Rules > Rulesets) | Require pull requests and approvals, block force pushes and deletions |
| Collaborators | Settings > Collaborators | Give someone write access to a personal repository |
| Personal access tokens | Profile Settings > Developer settings | Authenticate Git over HTTPS instead of a password |
| Fork | Top of a repository | Copy a repository to your account, to propose changes without write access |
| Issues | Issues tab | Track tasks, bugs, and discussions |
| Pull requests | Pull requests tab | Propose, review, and merge changes |
Git commands¶
| Command | Purpose |
|---|---|
git clone https://github.com/<owner>/<repo>.git |
Copy a GitHub repository to your computer |
git remote add origin <url> then git push -u origin main |
Publish an existing local repository to a new, empty GitHub repository |
git config --global credential.helper cache |
Remember a token in memory for a while, instead of typing it at each push |
git remote add upstream <url> |
Track the original repository from the clone of a fork |
git fetch upstream then git merge upstream/main |
Bring the original repository's new commits into your clone of a fork |
git pull --prune |
Update main after a merge, and forget remote branches deleted on GitHub |
git check-ignore -v <file> |
Show which .gitignore rule ignores a file |
What comes next¶
With repositories, access, and pull requests in place, the next steps are the GitHub features built around them: GitHub Projects for planning, GitHub Actions for automation, and the security and administration settings of repositories and organizations.