Close Menu
TGK Tech BlogTGK Tech Blog
    Facebook X (Twitter) Instagram
    • Contact Us
    X (Twitter) Instagram LinkedIn WhatsApp Telegram RSS
    TGK Tech BlogTGK Tech Blog
    • Home
    • AI

      SheBuilds on Lovable Season 04: How Women Can Apply for the Free 72-Hour AI Build Event

      September 26, 2026

      Top Tech Ambassador Programs to Apply for Right Now

      June 24, 2026

      DataCamp Free Access Week 2026: Get Unlimited Access to 680+ Courses for Free

      June 2, 2026

      10 Google Cloud Codelabs to Build AI Agents in 2026

      April 26, 2026

      How to Get the AWS AI & ML Scholarship 2026

      March 25, 2026
    • Cloud

      AWS Launches $500M Student Rewards Program: Here Is How to Claim Your Free Certification Voucher, Skill Builder, and Credits

      August 23, 2026

      Claim Your Free Redis Certification Before the Voucher Expires (100% OFF)

      August 22, 2026

      How to Get a Free AWS Certification Voucher (2026) – AWS Partner Guide

      August 13, 2026

      Microsoft is giving FREE Certification Exam Vouchers again

      July 29, 2026

      AWS re/Start Training and Certification Application for AWS Cloud Practitioner Cohort 16

      July 23, 2026
    • CyberSecurity

      Cybersecurity Roadmap 2026: From Beginner to Expert

      April 10, 2026

      Linux Foundation Training Scholarship 2026 Guide

      April 5, 2026

      GOMYCODE MASTERCLASS: Cyber Hygiene 101 – Protecting Yourself Online

      April 6, 2025

      Compete in the Cyber Games Challenge and Win Rewards

      March 31, 2025

      Should You Use a Free VPN? The Truth Revealed 🔍

      March 7, 2025
    • Software

      Moringa School Software Engineering Scholarship 2026

      October 30, 2026

      How to Get LinkedIn Premium + Microsoft 365 FREE for Students in 2026

      February 16, 2026

      Win KES 1M in Kenya’s Biggest App Dev Challenge!

      July 14, 2025

      Git Command Cheat Sheet

      April 12, 2025

      Visualize Your Codebase Like a Pro with GitDiagram

      March 29, 2025
    • Emerging Tech

      Digital Marketing Masterclass: How to Create a Facebook Ads Campaign from A to Z

      March 21, 2025

      Unlock Your Entrepreneurial Potential with the Tony Elumelu Foundation Entrepreneurship Programme!

      February 18, 2025

      Unlock Growth at Tech for Everyday Africa Luncheon!

      February 18, 2025

      Advance Your Career in Web3 & Emerging Technologies!

      February 18, 2025

      🎓 Ex-Candidates Mentorship Programme 2025 💡✨

      February 12, 2025
    • Startups

      Anthropic Offers Up to $50,000 in Free Claude API Credits

      July 29, 2026

      Daytona.io : The New Home for AI Startups

      May 1, 2025
    Subscribe
    TGK Tech BlogTGK Tech Blog
    Home » Software » Git Command Cheat Sheet
    Software

    Git Command Cheat Sheet

    Tech Group KenyaBy Tech Group KenyaApril 12, 2025Updated:October 27, 2026No Comments5 Mins Read
    Share Twitter Pinterest LinkedIn Reddit Telegram WhatsApp Threads Copy Link
    Share
    Twitter LinkedIn Reddit Telegram WhatsApp Threads Copy Link

    Setup & Configuration

    COMMANDDESCRIPTION
    git --versionCheck Git version
    git config --global user.name "Name"Set username globally
    git config --global user.email "[email protected]"Set email globally
    git config --listList all configurations
    git config --global core.editor "editor"Set default editor
    git config --global init.defaultBranch mainSet default branch name
    git config --global alias.<alias-name> "<git-command>"Create command alias

    Repository Initialization

    COMMANDDESCRIPTION
    git initInitialize a new Git repository
    git init --bareInitialize a bare repository
    git clone <repository-url>Clone a repository
    git clone --depth <depth> <repository-url>Clone with limited history
    git clone --branch <branch-name> <repository-url>Clone a specific branch

    Basic Operations

    COMMANDDESCRIPTION
    git statusShow working tree status
    git add <file>Add file to staging area
    git add .Add all files to staging area
    git add -pInteractively add changes
    git commit -m "message"Commit staged changes
    git commit -a -m "message"Add and commit all changes
    git commit --amendAmend the last commit
    git commit --amend --no-editAmend last commit without changing message

    Viewing Changes

    COMMANDDESCRIPTION
    git diffShow unstaged changes
    git diff --stagedShow staged changes
    git diff <commit1> <commit2>Compare two commits
    git diff <branch1> <branch2>Compare two branches
    git show <commit>Show a specific commit
    git logShow commit history
    git log --onelineShow commit history in one line format
    git log --graphShow commit history as a graph
    git log -pShow commit history with diffs
    git log --statShow commit history with stats
    git log --author="name"Filter commits by author
    git log --since="date"Filter commits since date
    git log --until="date"Filter commits until date
    git log --grep="pattern"Filter commits by pattern
    git blame <file>Show who changed each line in a file
    git reflogShow reference logs

    Undoing Changes

    COMMANDDESCRIPTION
    git restore <file>Discard changes in working directory
    git restore --staged <file>Unstage changes
    git reset <commit>Reset to a specific commit (keep changes)
    git reset --hard <commit>Reset to a specific commit (discard changes)
    git reset --soft <commit>Reset to a specific commit (keep staged)
    git revert <commit>Create a new commit that undoes changes
    git rm <file>Remove file from working directory and staging
    git rm --cached <file>Remove file from staging area only
    git clean -nShow what files would be removed
    git clean -fRemove untracked files
    git clean -fdRemove untracked files and directories

    Branching & Merging

    COMMANDDESCRIPTION
    git branchList local branches
    git branch -aList all branches (local and remote)
    git branch -rList remote branches
    git branch <branch-name>Create a new branch
    git branch -d <branch-name>Delete a branch
    git branch -D <branch-name>Force delete a branch
    git branch -m <new-name>Rename current branch
    git branch -m <old-name> <new-name>Rename specific branch
    git switch <branch-name>Switch to a branch
    git switch -c <branch-name>Create and switch to a new branch
    git checkout <branch-name>Switch to a branch (older method)
    git checkout -b <branch-name>Create and switch to a new branch (older method)
    git checkout -Switch to the previous branch
    git checkout <commit> <file>Checkout file from specific commit
    git merge <branch-name>Merge a branch into current branch
    git merge --no-ff <branch-name>Merge a branch creating a merge commit
    git merge --abortAbort a merge in case of conflicts
    git mergetoolLaunch merge conflict resolution tool

    Rebasing

    COMMANDDESCRIPTION
    git rebase <branch-name>Rebase current branch onto another
    git rebase -i <commit>Interactive rebase
    git rebase --abortAbort a rebase
    git rebase --continueContinue rebase after resolving conflicts
    git rebase --skipSkip current patch and continue

    Stashing

    COMMANDDESCRIPTION
    git stashStash changes
    git stash push -m "message"Stash changes with a message
    git stash listList stashes
    git stash show <stash@{n}>Show stash changes
    git stash apply <stash@{n}>Apply stash without removing
    git stash pop <stash@{n}>Apply stash and remove it
    git stash drop <stash@{n}>Remove a stash
    git stash clearRemove all stashes

    Remote Operations

    COMMANDDESCRIPTION
    git remoteList remotes
    git remote -vList remotes with URLs
    git remote add <name> <url>Add a new remote
    git remote remove <name>Remove a remote
    git remote rename <old-name> <new-name>Rename a remote
    git remote set-url <name> <url>Change remote URL
    git fetch <remote>Fetch from remote
    git fetch --allFetch from all remotes
    git pull <remote> <branch>Fetch and merge from remote
    git pull --rebase <remote> <branch>Fetch and rebase from remote
    git push <remote> <branch>Push to remote
    git push -f <remote> <branch>Force push to remote
    git push --set-upstream <remote> <branch>Push and set upstream
    git push <remote> --delete <branch>Delete remote branch
    git push --tagsPush tags to remote

    Tagging

    COMMANDDESCRIPTION
    git tagList tags
    git tag <tag-name>Create a lightweight tag
    git tag -a <tag-name> -m "message"Create an annotated tag
    git tag -d <tag-name>Delete a tag
    git push <remote> <tag-name>Push a tag to remote
    git push <remote> --tagsPush all tags to remote
    git checkout <tag-name>Checkout a tag

    Worktrees

    COMMANDDESCRIPTION
    git worktree listList worktrees
    git worktree add <path> <branch>Create a new worktree
    git worktree remove <path>Remove a worktree
    git worktree prunePrune worktree information

    Submodules

    COMMANDDESCRIPTION
    git submodule add <repository-url> <path>Add a submodule
    git submodule initInitialize submodules
    git submodule updateUpdate submodules
    git submodule update --init --recursiveInitialize and update all submodules recursively
    git submodule foreach <command>Execute command in each submodule

    Advanced Operations

    COMMANDDESCRIPTION
    git cherry-pick <commit>Apply changes from a specific commit
    git cherry-pick --continueContinue cherry-pick after resolving conflicts
    git cherry-pick --abortAbort a cherry-pick
    git rebase -i --autosquash <commit>Interactive rebase with autosquash
    git bisect startStart binary search for issues
    git bisect good <commit>Mark commit as good
    git bisect bad <commit>Mark commit as bad
    git bisect resetReset bisect state
    git grep <pattern>Search for pattern in tracked files
    git archive --format=zip HEAD > archive.zipCreate a zip archive of the repository
    git shortlogShow commit counts by author
    git shortlog -snShow commit counts sorted by number
    git rev-parse HEADGet full SHA-1 of current commit
    git rev-parse --short HEADGet short SHA-1 of current commit
    git fsckCheck repository integrity
    git gcGarbage collection
    git pruneRemove unreachable objects
    git verify-pack -v .git/objects/pack/*.idxVerify packed objects

    Gitflow Operations

    COMMANDDESCRIPTION
    git flow initInitialize gitflow in repository
    git flow feature start <name>Start a new feature
    git flow feature finish <name>Finish a feature
    git flow release start <version>Start a release
    git flow release finish <version>Finish a release
    git flow hotfix start <version>Start a hotfix
    git flow hotfix finish <version>Finish a hotfix

    Git Hooks

    COMMANDDESCRIPTION
    git hook listList available hooks
    .git/hooks/pre-commitPre-commit hook
    .git/hooks/commit-msgCommit message hook
    .git/hooks/post-commitPost-commit hook
    .git/hooks/pre-pushPre-push hook

    Troubleshooting

    COMMANDDESCRIPTION
    git fsckCheck repository integrity
    git gcGarbage collection
    git pruneRemove unreachable objects
    git verify-pack -v .git/objects/pack/*.idxVerify packed objects
    git count-objects -vCount objects and show size
    git show-refList references
    git reset --hardReset to HEAD discarding changes
    git clean -fdRemove untracked files and directories
    git reflog expire --expire=now --allExpire all reflog entries
    git gc --prune=nowGarbage collection with pruning
    git config --global --unset <config-name>Unset a config value

    Pdf Version Comming Soon on https://search.techgroupkenya.co.ke

    Git Git Comand Cheat Sheet
    Share. Twitter LinkedIn Reddit Telegram WhatsApp Threads Copy Link
    Previous ArticleGOMYCODE MASTERCLASS: Cyber Hygiene 101 – Protecting Yourself Online
    Next Article How to Get a Free Microsoft Certification Voucher via the AI Skills Fest Challenge (2025 Guide)
    Tech Group Kenya
    • Website

    tech community connecting developers, students, startups, and tech professionals across Kenya.

    Related Posts

    Software

    Moringa School Software Engineering Scholarship 2026

    October 30, 2026
    Software

    How to Get LinkedIn Premium + Microsoft 365 FREE for Students in 2026

    February 16, 2026
    Software

    Win KES 1M in Kenya’s Biggest App Dev Challenge!

    July 14, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Adverts
    X (Twitter) Instagram LinkedIn WhatsApp Telegram RSS
    • Subscribe
    • Terms of Service
    • Privacy Policy
    • Contact Us
    © 2026 TechyLabsy. Designed by TGK.

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.