๐Ÿง Linux & Git-GitHub Command Cheatsheet

Kanav GatheKanav Gathe
5 min read

๐Ÿ“‚ Linux File System Navigation

Basic Navigation

CommandDescriptionExample
pwdPrint working directorypwd
lsList files and directoriesls -la
cdChange directorycd /home/user
mkdirCreate directorymkdir new_folder
rmdirRemove empty directoryrmdir old_folder
touchCreate empty filetouch file.txt
rmRemove files or directoriesrm file.txt
cpCopy files or directoriescp source.txt dest.txt
mvMove/rename files or directoriesmv old.txt new.txt

File Viewing & Editing

CommandDescriptionExample
catDisplay file contentscat file.txt
lessView file contents page by pageless large_file.txt
headShow first lines of filehead -n 5 file.txt
tailShow last lines of filetail -n 10 file.txt
nanoSimple text editornano file.txt
vimAdvanced text editorvim file.txt

File Permissions

CommandDescriptionExample
chmodChange file permissionschmod 755 script.sh
chownChange file ownerchown user:group file.txt
sudoExecute command as superusersudo apt update

System Information

CommandDescriptionExample
unameShow system informationuname -a
dfShow disk space usagedf -h
duShow directory space usagedu -sh *
topShow running processestop
psList processesps aux

Package Management (Debian/Ubuntu)

CommandDescriptionExample
apt updateUpdate package listsudo apt update
apt installInstall packagesudo apt install package_name
apt removeRemove packagesudo apt remove package_name
apt upgradeUpgrade all packagessudo apt upgrade

๐ŸŒŸ Git Commands

Repository Setup

CommandDescriptionExample
git initInitialize new repositorygit init
git cloneClone repositorygit clone https://github.com/user/repo.git
git remoteManage remote repositoriesgit remote add origin URL

Basic Git Operations

CommandDescriptionExample
git statusCheck repository statusgit status
git addStage changesgit add file.txt
git commitCommit changesgit commit -m "message"
git pushPush changes to remotegit push origin main
git pullPull changes from remotegit pull origin main

Branching & Merging

CommandDescriptionExample
git branchList/create branchesgit branch feature
git checkoutSwitch branchesgit checkout feature
git mergeMerge branchesgit merge feature
git rebaseRebase branchesgit rebase main

History & Differences

CommandDescriptionExample
git logView commit historygit log --oneline
git diffShow file differencesgit diff file.txt
git blameShow file changes by linegit blame file.txt

Advanced Git Operations

CommandDescriptionExample
git stashTemporarily store changesgit stash save "message"
git resetReset changesgit reset --hard HEAD~1
git revertRevert commitsgit revert commit_hash
git tagManage tagsgit tag v1.0.0

๐ŸŒ GitHub Specific

Repository Management

CommandDescriptionExample
git forkFork repository (via GitHub UI)N/A
git pull requestCreate pull request (via GitHub UI)N/A

GitHub CLI Commands

CommandDescriptionExample
gh repo createCreate new repositorygh repo create my-project
gh pr createCreate pull requestgh pr create --title "Fix bug"
gh issue createCreate issuegh issue create --title "Bug report"

Best Practices ๐ŸŽฏ

  1. Always create a .gitignore file for your projects

  2. Write meaningful commit messages

  3. Use branches for features/bugs

  4. Regular commits and pushes

  5. Pull before pushing to avoid conflicts

  6. Review changes before committing

  7. Keep your local repository updated

Common Git Workflows ๐Ÿ”„

  1. Feature Branch Workflow

     git checkout -b feature/new-feature
     # Make changes
     git add .
     git commit -m "Add new feature"
     git push origin feature/new-feature
     # Create Pull Request on GitHub
    
  2. Hotfix Workflow

     git checkout -b hotfix/bug-fix main
     # Fix bug
     git add .
     git commit -m "Fix critical bug"
     git push origin hotfix/bug-fix
     # Create Pull Request on GitHub
    
5
Subscribe to my newsletter

Read articles from Kanav Gathe directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kanav Gathe
Kanav Gathe