Git and GitHub for Beginners: The Commands You Will Actually Use
The Qtec Mastery
Author
Every developer job advert in Kenya expects you to know Git, yet most beginners learn it by copying commands they do not understand. This guide to git and github for beginners covers the small set of commands you will use every day, in the order you will need them. By the end you will be able to save your work, try ideas on branches, put code on GitHub and undo mistakes without panic.
Git is a tool on your computer that records snapshots (commits) of your code so you can track changes and go back. GitHub is a website that stores Git projects online so you can back them up, share them and work with others. The daily loop is |
What is the difference between Git and GitHub?
Git and GitHub are often mentioned together, but they are different things.
- Git is free software that runs on your laptop. It works offline and keeps the full history of your project in a hidden
.gitfolder. - GitHub is an online service that hosts Git repositories. GitLab and Bitbucket do the same job.
A repository (or "repo") is simply a project folder that Git is tracking. A commit is a saved snapshot of that folder with a message explaining what changed.
For a junior developer, GitHub also works as a portfolio. A client or employer can open your profile and see real code you wrote, which is why we recommend it in our guide on how to become a web developer in Kenya.
How do I install and set up Git?
Install Git
- Windows: download Git for Windows from git-scm.com and accept the defaults. It includes Git Bash, a terminal for the commands below.
- Ubuntu or Debian Linux: run
sudo apt install git. - macOS: run
xcode-select --install, orbrew install gitif you use Homebrew.
Check it worked:
git --version
Tell Git who you are
Every commit records a name and email. Set them once per computer. Use the same email as your GitHub account so commits link to your profile.
git config --global user.name "Wanjiku Kamau"
git config --global user.email "wanjiku@example.com"
git config --global init.defaultBranch main
The last line makes new projects start on a branch called main, which matches GitHub.
Start a new repository or copy one
There are two ways to begin. To track a project you already have on your laptop, go into its folder and run git init:
cd school-portal
git init
To copy a project that already exists on GitHub, use git clone. This downloads the files and the full history:
git clone https://github.com/your-username/school-portal.git
cd school-portal
How do I save my work with add and commit?
Saving in Git is two steps. First you choose which changes to include (staging), then you record them (committing). This lets you commit related changes together.
git status # what has changed?
git add index.html # stage one file
git add . # or stage everything in this folder
git commit -m "Add student registration form"
git log --oneline # see your history
Run git status constantly. It tells you which files are changed, which are staged and which branch you are on.
Write commit messages that finish the sentence "This commit will...". "Add M-Pesa payment form" is useful six months later. "changes" and "final final" are not.
What are branches and how do I use them?
A branch is a separate line of work. You create one to build a feature or fix a bug without touching the working version on main. If the idea fails, you delete the branch and nothing is lost.
git switch -c add-payments # create a new branch and move to it
# ...edit files, then add and commit as usual...
git switch main # go back to main
git merge add-payments # bring the finished work into main
git branch -d add-payments # delete the branch once merged
You may see older tutorials use git checkout -b. It still works, but git switch is clearer and is the modern command for changing branches.
How do I push my code to GitHub and pull updates?
Connect your project to GitHub
- On GitHub, click New repository, give it a name and create it without a README (your project already has files).
- Copy the repository URL GitHub shows you.
- Link it and push:
git remote add origin https://github.com/your-username/school-portal.git
git push -u origin main
The -u flag remembers the link, so next time you can just type git push.
GitHub no longer accepts your account password for pushing over HTTPS. Sign in through the browser window Git for Windows opens, or use a personal access token, the GitHub CLI or an SSH key.
Get the latest changes
git pull
Run this before you start work each day, especially if teammates push to the same repository.
What should go in a .gitignore file?
Some files should never be committed: secrets, downloaded libraries and files your computer generates. List them in a file called .gitignore at the top of your project. For a Laravel or Node.js project it might look like this:
# secrets
.env
# dependencies (reinstall with composer install / npm install)
/vendor
/node_modules
# editor and system files
.vscode/
.DS_Store
Commit the .gitignore itself so everyone on the team gets the same rules. Laravel creates a sensible one for you in every new project.
What does a simple daily Git workflow look like?
git switch mainandgit pullto start from the latest code.git switch -c fix-login-errorto make a branch for today's task.- Work in small steps. After each working step,
git addandgit commit. git push -u origin fix-login-errorto back up the branch on GitHub.- Open a pull request on GitHub, get it reviewed and merge it.
Small, frequent commits are easier to understand and much easier to undo than one giant commit at the end of the week.
How do I undo mistakes safely?
Git is forgiving if you use the right command for the situation:
git restore index.html # throw away uncommitted changes to a file
git restore --staged index.html # unstage a file but keep your edits
git commit --amend -m "Better message" # fix the last commit (only if not pushed yet)
git revert a1b2c3d # undo a pushed commit by adding a new commit
Be careful with git restore index.html: it permanently discards changes you have not committed.
For anything already pushed, use git revert. It creates a new commit that reverses the old one, so history stays intact for everyone. Avoid git reset --hard and force-pushing on shared branches until you really understand them, because they rewrite history your teammates already have.
What is a pull request?
A pull request (PR) is a request on GitHub to merge one branch into another, usually your feature branch into main. It shows every changed line, lets teammates comment and approve, and can run automatic tests before anything is merged.
Even when you work alone, PRs are a good habit. They give you a clean record of what changed and why, and they are exactly how most software teams and open-source projects work day to day.
Common Git mistakes beginners make
- Committing the .env file. It holds database passwords, API keys and M-Pesa credentials. If it reaches GitHub, treat those secrets as leaked. Remove the file from tracking with
git rm --cached .env, add it to.gitignore, commit, and then change every secret in it, because the old values are still in the history. - Working directly on main. Use a branch for each task.
- Huge commits with vague messages. Commit small, describe clearly.
- Forgetting to pull. Pull before you start to avoid painful conflicts.
- Committing vendor or node_modules. These are rebuilt from
composer.jsonandpackage.json, so they belong in.gitignore.
Once Git is comfortable, a natural next step is learning how your code talks to other systems. Read What Is an API? for a beginner-friendly walk-through with an M-Pesa example.
Get confident with Git in four weeksOur Git, GitHub & DevOps Basics course takes you from your first commit to branches, pull requests and team workflows, all online (4 weeks, KES 5,000). Also useful: Backend Development (8 months, KES 60,000) |
Frequently asked questions
Is Git hard to learn?The daily commands take a few days to learn. Branching, merging and fixing conflicts take a few weeks of real use to feel natural. Is GitHub free?Yes. A free GitHub account includes unlimited public and private repositories, which is plenty for learning and personal projects. Should I use the terminal or a Git app?Learn the terminal commands first so you understand what is happening. After that, VS Code's built-in Git panel or GitHub Desktop is fine for everyday work. What happens if two people edit the same line?Git reports a merge conflict and marks both versions in the file. You choose the correct version, save, then |
Comments (0)
Search Blog
Categories
Popular Posts
Why Traditional Education is Failing Future Developers: The QTEC Approach
326 views
What Is Frontend Development? A Beginner's Guide
121 views
What Is a Database? A Beginner's Guide With Real Kenyan Examples
34 views
Git and GitHub for Beginners: The Commands You Will Actually Use
33 views
Computer Packages Course in Kenya: Fees, Duration and Certificate (2026)
31 views
You Might Also Like
What Is an API? How Apps Talk to Each Other (With an M-Pesa Example)
When you pay for something with M-Pesa on a website, check the weather on your p...
Read More →
How to Become a Web Developer in Kenya With No Experience: Step by Step
You can become a web developer in Kenya without a computer science degree and wi...
Read More →
What Is Frontend Development? A Beginner's Guide
Have you ever visited a website and thought, "Wow, this looks really good"? Mayb...
Read More →