Day-12 Linux - Git & GitHub Cheat Sheet

Day-12 Linux - Git & GitHub Cheat Sheet

Linux Commands:

Navigation:

CommandsUse Cases
pwdPrint current working directory
lsList files and directories
ls -lDetailed listing
ls -aShow hidden files
cdChange directory
cd ~Go to home directory
cd ..Move up one directory
mkdirCreate a new directory
mkdir my_folderCreate a directory name "my_folder"

File Operations:

CommandsUse Cases
touchCreate an empty file
touch new_file.txtCreate a file named "file.txt"
vim or nanoOpens text editor
vim new_file.txt or nano new_file.txtBoth will be used to edit text-based files
cpCopy files and directories
cp <option> <source> <destination>Copy file and directories to destination
mvMove or rename file
mv file.txt new_file.txtRename file
mv <option> <source> <destination>Move file to destination
rmRemove files and directory
rm file.txtRemove file
rm -r my_folderRemove directory and its contents
chmodChange file permission
chownChange file owner
chgrpChange file permission

Text Processing:

CommandsUse Cases
catConcatenate and display file content
cat file.txtDisplay contents of "file.txt"
grepSearch for pattern in files
grep "pattern" file.txtSearch for a pattern in :file.txt"
sedStream editor for text manipulation
sed 's/old/new/g' file.txtReplace all occurences of "old" with "new" in "file.txt"
awkPowerful pattern scanning and text processing tool
awk '{print $1}' file.txtPrint the first column of "file.txt"
head and tailDisplay the beginning or end of a file

System Information:

CommandsUse Cases
unamePrint system information
uname -aDisplay all system information
dfDisplay disk space usage
df -hHuman readable disk space usage
freeDisplay system memory usage
free -mDisplay memory usage in megabytes

Process Management:

CommandsUse Cases
psDisplay information about processes
ps auxDisplay detailed information about all processes
killTerminate a process
kill PIDTerminate the process with specified PID
topDisplay real time system statics
ifconfigDisplay network interface configuration
pingTest network connectivity
ping google.comPing google server

Package Management:

CommandsUse Cases
aptDebain/Ubuntu
apt updateUpdate package information
apt install packageInstall a package
apt remove packageRemove a package
apt search keywordSearch for a package
systemctlControl system services

User Management:

CommandUse Cases
useradd and userdelAdd or remove a user
passwdChange user password
su or sudoSwitch user or execute a command with superuser privileges

File Compression and Archives:

CommandsUse Cases
tarCreate or Extract tar archives
tar -cvf archiv.tar file1 file2Create a tar archive
tar -xvf archive.tarExtract file from a tar archive
gzip or gunzipCompress or decompress files
gzip file.txtCompress "file.txt"
gunzip file.txt.gzDecompress "file.txt.gz"

Git-GitHub Commands:

  • Git is the free and open source distributed version control system that's responsible for everything GitHub related that happens locally on your computer. This cheat sheet features the most important and commonly used Git commands for easy reference.

Git Basics:

  • Initialize a Repository:
CommandUse Cases
git initInitialize a new Git repository
  • Clone a Repository:
CommandUse Cases
git clone <repository_url>Clone a repository for URL
  • Stage and Commit:
CommandsUse Cases
git add <file>Stage changes for commit
git commi -m "commit message"Commit staged changes with a message
  • Branching:
CommandsUse Cases
git branchList branches
git branch <branch_name>Create a new branch
git checkout <branch_name> or git switch <branch_name>Switch to a branch
git merge <branch_name>Merge changes from another branch into the current branch
  • Remote Repositories:
CommandsUse Cases
git remote -vView remote repository
git remote add origin <repository_url>Add remote repository
git push -u origin <branch_name>Push changes to remote repository
git pull origin <branch_name>pull changes from a remote repository

Git Workflow:

  • Status and Changes:
CommandsUse Cases
git statusShow the status of changes
git diffShow changes between working directory and staging area
git diff --stagedShows changes between staging area and last commit
  • Log and History:
CommandsUse Cases
git logShow commit history
git log --onelineShow abbreviated commit history
  • Undoing Changes:
CommandsUse Cases
git reset Head <file>Unstage changes
git checkout --<file>Discard changes into working directory
git revert <commit_hash>Create a new commit to reverse changes from a specific commit
  • Tagging:
CommandsUse Cases
git tag <tag_name>Create a lightweight tag for the current commit
git tag -a <tag_name> -m "Tag message"Create an annotated tag with the message
  • Collaboration:
CommandsUse Cases
git fetchFetch changes from the remote repository
git branch -d <branch_name>Delete a local branch
git push origin --delete <branch_name>Delete a remote branch
  1. Forking:

    • Fork a repository on GitHub
  2. Cloning Forked Repository:

    • Clone the forked repository to your local machine
  3. Upstream Connection:

    • git remote add upstream <original_repository_url>: Add upstream repository for updates
  4. Keeping Fork Updated:

    • git fetch upstream: Fetch updates from the upstream repository

    • git merge upstream/main: Merge updates into your local main branch

    • git push origin main: Push updates to your fork on GitHub

  5. Pull Requests:

    • Create a new branch for your feature or bug fix

    • Commit changes and push the branch to your fork

    • Open a pull request from your branch to the upstream repository


Happy Learning

Thanks For Reading! :)

-SriParthu💝💥