Version: Jun 28, 2026

Git - Maybe a cheat sheet

TLDR: Lets talk about Git commands for linux terminal and git ignore file.

I think like most people, we all end up using GUI applications (like SmartGit or Git-Fork) to do our git actions. In this blog post, I want to provide some stragiht forward commands to let you move on to the next thing in your jou Journey.

Also some nice to knows about the .gitignore file that beginners may like to know quickly.


🌿 Move Back to Main

# Show the current branchgit branch --show-current
# Show local changes before switching branchesgit status
# Fetch latest remote branch info and prune deleted remote branchesgit fetch --prune origin
# Switch to maingit switch main
# Older syntax for switching to maingit checkout main
# Pull latest main from origingit pull origin main
# Create local main if it does not exist yetgit switch -c main --track origin/main
# Confirm the working tree is cleangit status
# Show the latest commitsgit log --oneline -5

🌱 Move to Another Branch

# Show the current branchgit branch --show-current
# Show local changes before switching branchesgit status
# Fetch latest remote branch info and prune deleted remote branchesgit fetch --prune origin
# Local Branches. Anything marked with '[gone]' means its locally exists only.git branch -vv
# Remote Branches.git branch -r
# Both Local and Remote Branchesgit branch -a
# Good old force delete of local branches (only if your 100% sure)git branch -D NameOfBranch
# Switch to an existing branch, only if it already exists on your systemgit switch branch-name
# pulling a new branch from origingit switch -c NameOfYourBranch --track origin/NameOfYourBranch
# Older syntax for switching to an existing branchgit checkout branch-name
# Pull latest branch from origingit pull origin branch-name
# Create a local branch tracking a remote branchgit switch -c branch-name --track origin/branch-name
# Show all local branchesgit branch
# Show local and remote branchesgit branch -a
# Confirm the working tree is cleangit status
# Show the latest commitsgit log --oneline -5

📁 .gitignore

Ignore everything in a folder except one file

/folder/*
!/folder/keep-me.txt

Ignore everything and subfolders too

**/folder/*

Without the /* at the end, it'll ignore everything regardless if you ass to negate ignore with the !

General ignores

Lots of projects and sites usually give you a .gitignore ready to go to easily kick off your project, even by language type. Eg, starting a Rust project versus C# project, different things are ignored. How and where? When creating a project in GitHub, you'll see your repo being kicked off with a chance to select a pre-made gitignore file for you.

Anyways! Below is a taste just in case you don't run into this. This really serves beginners, but you beginner, I recommend heading to GitHub and start playing around with your first repo.