Linux / Git Basics
Git Basics

Git Basics

A hands-on guide to version control with Git – from initialising repos and committing changes to branching, merging, and collaborating on GitHub in engineering workflows.

Version Control Branching Merging Remote Repos GitHub Workflow

Essential command reference

Setup and init
# Set global identity
git config --global user.name "Olisaeloka Michael"
git config --global user.email "your@email.com"

# Initialise a new repo
git init my-project
cd my-project

# Clone an existing repo
git clone https://github.com/olisamichaeltech/repo.git
Stage, commit, push
# Check what has changed
git status

# Stage all changes
git add .

# Commit with a message
git commit -m "feat: add nginx config"

# Push to remote branch
git push origin main
Branching and merging
# Create and switch to a new branch
git checkout -b feature/azure-arc-setup

# List all branches
git branch -a

# Merge a branch into main
git checkout main
git merge feature/azure-arc-setup

# Delete branch after merge
git branch -d feature/azure-arc-setup
Undo and recover
# Discard unstaged changes
git restore filename.sh

# Undo last commit (keep changes)
git reset --soft HEAD~1

# Stash work in progress
git stash
git stash pop