What is Git?
Git is a version control system that enables developers to track and manage changes locally while syncing them with remote repositories. It allows multiple people to work on a project simultaneously, maintains a history of modifications and makes it easy to revert to previous versions when needed.

1. Setting Up Git
-
Install Git on your system if it is not already installed.
Installation Instructions - Verify the Git installation by checking the version.
git --version - Configure user information (this ensures that your commits are correctly attributed to you)
git config --global user.name "Your Name" git config --global user.email "user@example.com" - Confirm the configuration
git config --list
2. Initialise a Git Repository
To facilitate this demo, we’ll use a simple “To-Do List Tracker”, a basic text-based to-do list. We’ll use Git to track changes while demonstrating commands like init, add, commit, log, branch, merge, and push.
- Create a new project folder:
mkdir git-demo-todo-list cd git-demo-todo-list - Initialise Git:
git init - Verify that Git has been initialised by listing all files (including hidden ones):
ls -laThe
.gitfolder is where Git stores all information about your repository. It acts as Git’s brain, tracking changes, storing history, and managing branches.
3. Tracking Files in Git
- Let’s start by creating a simple to-do file.
touch todo.txt echo "Initial To-Do List" > todo.txt - Check the current Git status of our repository.
git statusWhat we see: - Branch: main - `main` branch is the default one. - No commits - Untracked todo.txt - Add the file to staging.
git add todo.txt - Commit the file:
git commit -m "Add initial todo list"
4. Making Changes and Checking History
- Modify todo.txt:
echo "- Learn Git basics" >> todo.txt - Check differences:
git diff - Add & commit changes:
git add todo.txt git commit -m "Add new todo item" - View commit history:
git log
5. Creating and Switching Branches
- Create a new branch:
git branch feature-branch - Switch to the new branch:
git checkout feature-branch - Modify & commit changes:
echo "Feature branch update" > feature.txt git add feature.txt git commit -m "Added feature.txt"
6. Merging Branches
- Switch back to main:
git checkout main - Merge feature-branch:
git merge feature-branch - Delete the merged branch:
git branch -d feature-branch
7. Using Git Stash
Sometimes, you may need to temporarily save your changes without committing them.
- Create and switch to a new branch:
git checkout -b stash-branch - Modify todo.txt:
echo "- Learn Git Stash" >> todo.txtAt this point, you might want to switch to main branch to work on something else. Git Stash allows you to save your uncommitted changes and restore them later.
- Stash your changes:
git stashThis saves your changes and restores your working directory to a clean state. You can safely switch branches or pull changes without worrying about losing your work.
Alternatively, you could stash with a name to make it easier to identify a specific stash.
git stash push -m "Working on Git Stash" - View your stashed changes:
git stash listEach stash is saved with an index (e.g., stash@{0}) and optionally a name, making it easy to identify and retrieve later.
-
Using the stashed changes:
When you come back to use your changes at a later point, you have a few options:- Apply the most recent stashed changes while keeping the stash entry in the list:
git stash apply - Apply a specific stash from the list by using its index:
git stash apply stash@{1} - Apply the most recent stash and remove the entry from the list:
git stash pop - Drop a specific stash when you no longer need it:
git stash drop stash@{1}
- Apply the most recent stashed changes while keeping the stash entry in the list:
- To clear all stashed changes, use:
git stash clear
8. Working with a Remote Repository (GitHub)
For this tutorial, we’ll use GitHub. You will need to create an account.
- To confirm your username and email settings, use:
git config user.name git config user.emailYou can change the config at any time for a particular repository by omitting the
--globalflag.git config user.name "Your GitHub User Name" git config user.email "Your GitHub Email" - Create a remote repository on GitHub and copy the url to the repository.
- Link the local repository to the remote:
git remote add origin <repo-url> - Push code:
git push -u origin main - Pull changes:
git pull origin main

You’ve now covered the essentials of Git, from setting up a repository to branching, merging, and syncing with GitHub. These skills lay the foundation for effective version control and collaboration.
Coming soon in Part 2, we’ll tackle collaboration workflows and resolving merge conflicts — key skills for working on real-world projects. Stay tuned!
In the next post, we’ll tackle collaboration workflows and resolving merge conflicts — key skills for working on real-world projects. Continue to Learn Git: Collaboration Workflow.