Git and GitHub can feel overwhelming when you’re starting out. They’re two tools doing one job. Git tracks changes to your code. GitHub hosts that code online so people can work on it together. Everything below walks through getting your first pull request merged.
Git versus GitHub
Git lives on your computer. It records snapshots of your project so you can rewind, branch, and experiment safely. GitHub is a website that hosts Git repositories online. That’s where your code gets a home on the internet, and where other people can see it and collaborate.
Step 1: Install and configure Git
Install Git from git-scm.com or through your package manager. Then tell Git who you are. That identity gets attached to every commit you make.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Use the same email as your GitHub account so your commits get linked to your profile.
Step 2: Your first repository
Create a folder, drop a file in it, and turn it into a repository.
mkdir my-first-repo
cd my-first-repo
git init # start tracking this folder
echo "# Hello DevSoc" > README.md
git add README.md # stage the file
git commit -m "Add README" # save a snapshot
git init starts tracking the folder. git add stages the file. git commit saves a snapshot. You can see your history anytime with git log.
Step 3: Get the project onto GitHub
Create a new repository on github.com/new. Don’t tick the box that initializes it with a README, since your folder already has one. Then push your local repo up.
git remote add origin https://github.com/your-username/my-first-repo.git
git push -u origin main
Refresh the page and your code is online.
Step 4: Branches
A branch is a separate line of development. It lets you try things without touching the main code.
git checkout -b my-feature # create and switch to a new branch
# ... make your changes ...
git add .
git commit -m "Add my feature"
Step 5: Your first pull request
A pull request is a proposal. It says, here are changes I made on my branch, please review and merge them into main.
- Push your branch:
git push -u origin my-feature - On GitHub, click Compare & pull request.
- Write a short title and describe what you changed.
- Click Create pull request.
- Once a reviewer approves it, click Merge pull request.
Commands you’ll use constantly
git status # what's changed?
git add <file> # stage changes
git commit -m "message" # commit staged changes
git pull # get the latest changes
git push # upload your commits
git branch # list branches
git checkout -b <name> # new branch
Practice, don’t memorize
You don’t need to memorize Git. Everyone searches for commands. What matters is understanding the flow. Branch, change, commit, push, pull request, merge. Run through it once on a practice repo and it’ll stick.
DevSoc members who want a safe place to practice can open an issue or PR in any of our project repos. A committee member will walk you through it. Version control is a skill worth building, and it only gets easier with practice.
