๐ง Linux & Git-GitHub Command Cheatsheet
Kanav Gathe
5 min read
๐ Linux File System Navigation
Basic Navigation
Command | Description | Example |
pwd | Print working directory | pwd |
ls | List files and directories | ls -la |
cd | Change directory | cd /home/user |
mkdir | Create directory | mkdir new_folder |
rmdir | Remove empty directory | rmdir old_folder |
touch | Create empty file | touch file.txt |
rm | Remove files or directories | rm file.txt |
cp | Copy files or directories | cp source.txt dest.txt |
mv | Move/rename files or directories | mv old.txt new.txt |
File Viewing & Editing
Command | Description | Example |
cat | Display file contents | cat file.txt |
less | View file contents page by page | less large_file.txt |
head | Show first lines of file | head -n 5 file.txt |
tail | Show last lines of file | tail -n 10 file.txt |
nano | Simple text editor | nano file.txt |
vim | Advanced text editor | vim file.txt |
File Permissions
Command | Description | Example |
chmod | Change file permissions | chmod 755 script.sh |
chown | Change file owner | chown user:group file.txt |
sudo | Execute command as superuser | sudo apt update |
System Information
Command | Description | Example |
uname | Show system information | uname -a |
df | Show disk space usage | df -h |
du | Show directory space usage | du -sh * |
top | Show running processes | top |
ps | List processes | ps aux |
Package Management (Debian/Ubuntu)
Command | Description | Example |
apt update | Update package list | sudo apt update |
apt install | Install package | sudo apt install package_name |
apt remove | Remove package | sudo apt remove package_name |
apt upgrade | Upgrade all packages | sudo apt upgrade |
๐ Git Commands
Repository Setup
Command | Description | Example |
git init | Initialize new repository | git init |
git clone | Clone repository | git clone https://github.com/user/repo.git |
git remote | Manage remote repositories | git remote add origin URL |
Basic Git Operations
Command | Description | Example |
git status | Check repository status | git status |
git add | Stage changes | git add file.txt |
git commit | Commit changes | git commit -m "message" |
git push | Push changes to remote | git push origin main |
git pull | Pull changes from remote | git pull origin main |
Branching & Merging
Command | Description | Example |
git branch | List/create branches | git branch feature |
git checkout | Switch branches | git checkout feature |
git merge | Merge branches | git merge feature |
git rebase | Rebase branches | git rebase main |
History & Differences
Command | Description | Example |
git log | View commit history | git log --oneline |
git diff | Show file differences | git diff file.txt |
git blame | Show file changes by line | git blame file.txt |
Advanced Git Operations
Command | Description | Example |
git stash | Temporarily store changes | git stash save "message" |
git reset | Reset changes | git reset --hard HEAD~1 |
git revert | Revert commits | git revert commit_hash |
git tag | Manage tags | git tag v1.0.0 |
๐ GitHub Specific
Repository Management
Command | Description | Example |
git fork | Fork repository (via GitHub UI) | N/A |
git pull request | Create pull request (via GitHub UI) | N/A |
GitHub CLI Commands
Command | Description | Example |
gh repo create | Create new repository | gh repo create my-project |
gh pr create | Create pull request | gh pr create --title "Fix bug" |
gh issue create | Create issue | gh issue create --title "Bug report" |
Best Practices ๐ฏ
Always create a
.gitignore
file for your projectsWrite meaningful commit messages
Use branches for features/bugs
Regular commits and pushes
Pull before pushing to avoid conflicts
Review changes before committing
Keep your local repository updated
Common Git Workflows ๐
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
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.
Git CommandsGitHubGitLinux#DevOps #Git #GitHub #VersionControl #LearnDevOps #TechSkills #GitForDevOps #DevOpsEngineerDevopscheatsheetCommands
Written by