Skip to main content

Command Palette

Search for a command to run...

🐧 The Ultimate Linux & Git-GitHub Cheat Sheet for DevOps πŸ› οΈ

Updated
β€’9 min readβ€’View as Markdown
🐧 The Ultimate Linux & Git-GitHub Cheat Sheet for DevOps πŸ› οΈ
M

Tech enthusiast | Code craftsman | DevOps explorer | Turning bugs into features one line at a time πŸš€

This cheat sheet will cover Linux commands, Git commands, and GitHub essentials, with descriptions, examples, and real-world relevance.

🐧 Linux Commands for Everyday Use

CommandDescriptionExample
whoamiDisplays the current logged-in user.whoami
uname -rDisplays the Linux kernel version.uname -r
df -hShows disk usage in a human-readable format.df -h
du -sh [directory]Shows the size of a directory or file.du -sh /home/user
ls -laLists all files and directories with detailed information.ls -la
pwdPrints the current working directory.pwd
mkdir [directory]Creates a new directory.mkdir project_folder
rm -rf [directory/file]Deletes files or directories (use with caution).rm -rf old_files
chmod [permissions] [file]Changes file permissions.chmod 755 script.sh
chown [user]:[group] [file]Changes ownership of a file or directory.chown user:group file.txt
ps -auxDisplays all running processes.ps -aux
kill [process_id]Terminates a process by its PID.kill 1234
historyShows command history.history
alias [name]='[command]'Creates a shortcut for a command.alias ll='ls -la'
curl [url]Fetches data from a URL.curl https://example.com
wget [url]Downloads a file from a URL.wget https://example.com/file.zip
scp [file] [user@host:/path]Securely copies files between local and remote systems.scp file.txt user@192.168.1.1:/tmp
ssh [user@host]Connects to a remote server via SSH.ssh user@192.168.1.1

πŸ” Text Processing Commands.

CommandDescriptionExample
find [directory] -name "[name]"Searches for files by name.find /home -name "*.txt"
awk '/pattern/ {action}' [file]Processes text based on patterns in files.awk '/error/ {print $2}' log.txt
sed -i 's/[old]/[new]/g' [file]Finds and replaces text in a file.sed -i 's/foo/bar/g' file.txt
sort [file]Sorts lines in a file.sort data.txt
uniq [file]Removes duplicate lines from a file.uniq data.txt
wc -l [file]Counts the number of lines in a file.wc -l file.txt
grep [pattern] [file]Searches for a pattern in a file.grep "error" log.txt
crontab -eEdits the crontab to schedule recurring tasks.crontab -e

🌐 Networking Commands

CommandDescriptionExample
ping [host]Tests connectivity to a server.ping google.com
netstat -tulnDisplays open ports and network connections.netstat -tuln
ip aDisplays IP address and network details.ip a
scp [file] [user@host:/path]Copies files between local and remote systems.scp backup.zip user@192.168.1.1:/tmp
ssh [user@host]Connects to a remote server via SSH.ssh user@192.168.1.1
curl -I [url]Fetches HTTP headers for a URL.curl -I https://example.com

πŸ› οΈ Git Essentials

CommandDescriptionExample
git initInitializes a Git repository in the current directory.git init
git clone [url]Creates a local copy of a remote repository.git clone https://github.com/user/repo.git
git statusShows the status of changes in the working directory.git status
git add [file]Stages a file for commit.git add README.md
git commit -m "[message]"Saves staged changes with a commit message.git commit -m "Initial commit"
git push origin [branch]Pushes changes to the remote repository.git push origin main
git pull origin [branch]Fetches and merges changes from a remote repository.git pull origin main
git branchLists all branches in the repository.git branch
git checkout -b [branch]Creates and switches to a new branch.git checkout -b feature-branch
git merge [branch]Merges a branch into the current branch.git merge feature-branch
git logDisplays the commit history.git log

🌟 GitHub Essentials

ActionDescriptionSteps
Create a RepositorySets up a new repository on GitHub.Go to GitHub β†’ Click on "New" β†’ Fill details.
Clone a RepositoryCopies an existing repository to your local system.git clone [url]
Push ChangesUpdates the remote repository with local changes.git push origin main
Pull RequestsProposes changes to a branch.Navigate to your branch β†’ Click "Pull Request".

Introduction

In the world of DevOps, Git and GitHub are essential tools that help developers work together and manage their code.

What is Git?🌿🐱

Definition: Git is a distributed version control system that helps developers track changes in their code, collaborate with others, and manage software development efficiently.

Key Aspects of Git:

  1. Version Control: Tracks code changes effectively.

  2. Branching: Isolates different feature developments.

  3. Collaboration: Enables smooth teamwork and contributions.

  4. Remote repositories facilitate easy code sharing and backups.

  5. Pull Requests: Allow code review before merging.

Fundamental Concepts in Git:

  1. Commits: Snapshots of code changes.

  2. Repositories: Collection of code and history.

  3. Working Directory: Where developers make changes.

  4. Staging Area: Prepares changes for commits.

  5. Push and Pull: Sending and fetching changes.

  6. Merge and Conflict Resolution: Combining changes and handling conflicts.

  7. Branches: Separate development paths for features.

  8. Forks: Personal copies for independent development.

What is GitHub?

Definition: GitHub is a web-based hosting service that uses Git for version control. It provides a platform for developers to store, manage, and collaborate on code repositories.

Key Aspects:

  1. Code Hosting: Store code online.

  2. Collaboration: Work together on projects.

  3. Community and Open Source: Global developer community.

  4. Issue Tracking: Manage project issues.

  5. CI/CD Integration: Automate testing and deployment.

What is Version Control? How many types of version controls we have?

Version control is a system that helps you manage changes to your files and code over time. It keeps track of different versions of your work, allowing you to go back to previous states, collaborate with others, and avoid conflicts. It's like having a time machine for your project, so you can undo mistakes and track progress.

There are mainly two types of version control:

  1. Centralized Version Control (CVC): In CVC, there is a central server that stores all the project files and their versions. When team members want to work on the project, they check out a copy from the central server, make changes, and then commit those changes back to the server. Examples of CVC systems include Apache Subversion (SVN) and Perforce.

  2. Distributed Version Control (DVC): DVC, on the other hand, doesn't rely on a central server. Each team member has a complete copy of the entire project, including its history. They can work independently and synchronize their changes directly with each other. Examples of DVC systems include Git and Mercurial.

CVCS vs DVCS

Sr. No.KeyCentralized Version ControlDistributed Version Control
1WorkingIn CVS, a client need to get local copy of source from server, do the changes and commit those changes to centeral source on server.In DVS, each client can have a local branch as well and have a complete history on it. Client need to push the changes to branch which will then be pushed to server repository.
2Learning CurveCVS systems are easy to learn and set up.DVS systems are difficult for beginners. Multiple commands needs to be remembered.
3BranchesWorking on branches in difficult in CVS. Developer often faces merge conflicts.Working on branches in easier in DVS. Developer faces lesser conflicts.
4Offline AccessCVS system do not provide offline access.DVD systems are workable offline as a client copies the entire repository on their local machine.
5SpeedCVS is slower as every command need to communicate with server.DVS is faster as mostly user deals with local copy without hitting server everytime.
6BackupIf CVS Server is down, developers cannot work.If DVS server is down, developer can work using their local copies.

Setting Up Your Local Repository:

  1. Install Git on your computer.
    Click here for download git in your system

  2. Configure your name and email in Git.

  3. Open the terminal or command prompt.

  4. Navigate to the directory where you want to create your repository.

  5. Initialize a new Git repository using git init.

  6. Add your files to the staging area with git add.

  7. Make your first commit using git commit.

  8. Create a remote repository on GitHub (optional).

  9. Link your local repository to the remote one using git remote add origin.

  10. Push your code to the remote repository with git push origin.

Your local repository is now set up and ready to track changes and collaborate with others using Git.

Git Commands

  • git init: Initializes a new Git repository in the current directory.

  • git add <file_name>: Stages (adds) a file to be included in the next commit. Use git add . to stage all changes.

  • git status: Shows the current status of your working directory, including modified files and staged changes.

  • git log: Displays the commit history, showing the commit IDs, authors, dates, and commit messages.

  • git diff: Compare changes between files, showing line-by-line differences between versions.

  • git commit -m "Commit message": Creates a new commit with the changes that you have staged. The commit message should briefly describe the changes made.

  • git branch: Lists all branches in the repository. Use git branch <branch_name> to create a new branch.

  • git checkout <branch_name>: Switches to a different branch.

  • git merge <branch_name>: Merges changes from a different branch into the current branch.

  • git clone <repository_url>: Clones (downloads) a remote repository to your local machine.

  • git pull: Fetches and merges changes from the remote repository into your local branch.

  • git push: Pushes your local commits to the remote repository.

  • git stash: Temporarily saves changes for later use without committing.

  • git cherry-pick: Applies a specific commit from one branch to another.

More from this blog

Untitled Publication

78 posts