Bytebook Compiler

Developer Tools

Git & GitHub

Version control for every project: repositories, the staging area, commits, history, branches and merging, and sharing work on GitHub with push, pull, clones and pull requests.

4 min read4-question quiz

Git is a version control system: it records snapshots of your project over time so you can see what changed, go back to any earlier version, and work with others without overwriting each other's work. GitHub is a website that hosts Git repositories online — and doubles as your public developer portfolio.

Why version control?

  • Never lose work — every commit is a restore point.
  • Understand history — who changed what, when, and why.
  • Experiment safely — try ideas on a branch; throw them away if they fail.
  • Collaborate — many people work on one codebase in parallel.

The three areas

Area What lives there
Working directory the files you are editing right now
Staging area (index) changes you have marked for the next commit
Repository (.git folder) the permanent history of commits
Edit files in the working directorygit add — stage the changes you wantgit commit — save a snapshot with a messagegit push — upload commits to GitHubTeammates git pull to get them
The everyday Git workflow.

First-time setup

Terminal
git config --global user.name "Asha Rao"
git config --global user.email "asha@example.com"
git config --global init.defaultBranch main

Starting and saving work

Terminal
git init                          # turn the current folder into a repository
git status                        # what changed? what is staged?
git add main.c                    # stage one file
git add .                         # stage everything in this folder
git commit -m "Add linked list insert and delete"
git log --oneline                 # history, one line per commit
git diff                          # unstaged changes, line by line

.gitignore

List files Git should never track — compiled programs, secrets, editor clutter:

Text
# .gitignore
a.out
*.o
*.exe
__pycache__/
.env
node_modules/
.vscode/

Undoing things

Terminal
git restore main.c                # discard unstaged edits to a file
git restore --staged main.c       # unstage, keeping the edits
git commit --amend                # fix the last commit's message or contents
git revert a1b2c3d                # make a new commit that undoes an old one
git checkout a1b2c3d -- notes.txt # bring back an old version of one file

Branches

A branch is an independent line of development. main holds working code; you create a branch for each feature or fix, then merge it back.

Terminal
git branch                        # list branches
git switch -c feature/stack       # create and switch to a new branch
# ... edit and commit on the branch ...
git switch main                   # go back to main
git merge feature/stack           # bring the branch's commits into main
git branch -d feature/stack       # delete the merged branch

If both branches changed the same lines, Git reports a merge conflict and marks the file:

Text
<<<<<<< HEAD
printf("Hello\n");
=======
printf("Hello, world!\n");
>>>>>>> feature/greeting

Edit the file to keep the right version, delete the markers, then git add and git commit.

Working with GitHub

Terminal
git clone https://github.com/user/repo.git      # download a repository
git remote add origin https://github.com/you/project.git
git push -u origin main                          # upload your commits (first time)
git push                                         # later pushes
git pull                                         # fetch and merge others' changes

Pull requests (PRs): on GitHub, push your branch, then open a pull request asking to merge it into main. Teammates review the changes and comment before merging — the standard workflow in every software company.

Forks: copy someone else's repository to your account, change it, then open a PR back to the original — how open-source contributions work.

Command Purpose
git init / git clone start a repository / copy one
git status, git diff, git log inspect
git add, git commit save a snapshot
git switch -c, git merge branch and merge
git push, git pull sync with GitHub
git restore, git revert undo

Test yourself

4 questions · pick an answer to check it instantly

  1. 1

    Which command moves changes into the staging area?

  2. 2

    What does git push do?

  3. 3

    Which file tells Git which files to ignore?

  4. 4

    What is a pull request?