Git Introduction

Cloud | AWS | DevOps | AI 📍 Toronto 🇨🇦 🚀 Cloud Architect @ AWS 👨🏽🏫 Professor
Git is the most popular version control system used by developers around the world. It helps track changes in your code, collaborate with others, and manage project versions efficiently. Whether you're working solo or as part of a team, Git ensures your work is organized and never accidentally lost.
In this blog, we'll walk you through the following:
Understanding Git basics.
Installing Git on Ubuntu.
Creating a GitHub repository.
Pushing the
index.htmlfile that was shown in this blog to a GitHub repository.
Introduction to Git
What is Git?
Git is a distributed version control system designed to manage changes in files, especially code, efficiently. It allows developers to:
Track changes over time.
Collaborate with multiple people without conflicts.
Revert to previous versions if needed.
Why Use Git?
Versioning: Always have access to previous versions of your code.
Collaboration: Multiple developers can work on the same project simultaneously.
Backup: Your codebase is stored safely in remote repositories like GitHub.
Installing Git on Ubuntu
To use Git, you need to install and configure it on your machine.
To follow along with the rest of this blog, I am assuming the following:
You have a Github account
You have a working Ubuntu environment
Update the Package Manager
Open your terminal and update the package manager to ensure you have the latest package information:
sudo apt update
Install Git
Install Git using the following command:
sudo apt install git
Verify the Installation
Check if Git is installed correctly by running:
git --version
You should see something like:
git version 2.x.x
Configure Git
Set up your identity, which will be attached to your commits. This will be your github password and email.
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
To confirm your configuration, run:
git config --list
Creating a GitHub Repository
GitHub is a cloud-based service that hosts Git repositories. Here’s how to create one:
Log in to GitHub
Go to Github and log in or sign up for an account.
Create a New Repository
Click on the + icon in the top-right corner and select New Repository.
Provide a repository name (e.g.,
my-resume-site).Choose visibility:
Public: Anyone can view it.
Private: Only you and your collaborators can view it.
PS: I recommend using Private
Check “Initialize this repository with a README” option.
Click Create repository.4. Adding and Pushing Your
index.htmlFile
Now that your GitHub repository is ready, let’s add and push your index.html file to it.
Create a Local Project Directory
Move to your home directory
cd ~Create a new folder for your project and move into it:
mkdir my-resume-site cd my-resume site
Create the index.html File
Create a simple
index.htmlfile:vi index.htmlCopy paste the index.html file contents from this blog to this file and save it.
Confirm file exists
cat index.html
Initialize Git
Initialize Git in your project directory:
git init
Stage Your File
Add the index.html file to Git’s staging area:
git add index.html
Commit Your Changes
Save your changes to Git with a meaningful message:
git commit -m "Initial commit: Add index.html"
Link to Your GitHub Repository
Link your local repository to the GitHub repository you created earlier. Replace <yourusername> and <reponame> with your GitHub username and repository name:
git remote add origin https://github.com/<yourusername>/my-resume-site.git
Push Your Code to GitHub
Push your code to the main branch of your GitHub repository:
git branch -M main
git push -u origin main
Recap on what we did so far

Verifying Your Upload
Open your GitHub repository in a browser.
You should see your
index.htmlfile.Click on the file to view its contents.
Going further
Now that your code is on GitHub, you can:
Update the file and push changes using
git add,git commit, andgit push.Clone the repository to other machines using
git clone.Collaborate with others by inviting them to your repository.
Git Cheatsheet
The below table shows most commands that a developer would use in development while using Git.
| Command | Description | Example Usage |
git init | Initialize a new Git repository | git init |
git clone <repo_url> | Clone a repository | git clone https://github.com/user/repo.git |
git status | Show the status of your working directory | git status |
git add <file> | Stage changes to be committed | git add file.txt |
git add . | Stage all changes in the current directory | git add . |
git commit -m "<message>" | Commit staged changes with a message | git commit -m "Added new feature" |
git push | Push commits to the remote repository | git push origin main |
git pull | Fetch and merge changes from the remote | git pull origin main |
git branch | List branches | git branch |
git branch <branch_name> | Create a new branch | git branch feature-branch |
git checkout <branch> | Switch to a branch | git checkout feature-branch |
git checkout -b <branch> | Create and switch to a new branch | git checkout -b feature-branch |
git merge <branch> | Merge a branch into the current branch | git merge feature-branch |
git log | Show commit history | git log |
git log --oneline | Show concise commit history | git log --oneline |
git diff | Show changes in tracked files | git diff |
git diff <branch1> <branch2> | Compare two branches | git diff main feature-branch |
git stash | Temporarily save changes without committing | git stash |
git stash pop | Apply the last stashed changes | git stash pop |
git reset <file> | Unstage a file | git reset file.txt |
git reset --hard <commit> | Reset working directory to a specific commit | git reset --hard abc1234 |
git remote -v | Show remote repositories | git remote -v |
git remote add <name> <url> | Add a remote repository | git remote add origin https://github.com/user/repo.git |
git tag <tag_name> | Create a tag for a specific commit | git tag v1.0.0 |
git fetch | Fetch changes from remote without merging | git fetch origin |
git rebase <branch> | Reapply commits on top of another branch | git rebase main |
git cherry-pick <commit> | Apply a specific commit to the current branch | git cherry-pick abc1234 |
By mastering Git, you’ll streamline your development workflow and enhance collaboration on any project.
Happy coding!






