Table of contents
Introduction
Welcome DevOps enthusiasts. In DevOps, expertise in Linux and Git is paramount. Keeping that in mind this blog will be focusing on creating a concise bundle of commands, what most people call a "Cheat-Sheet".
What's new? The catch here is, every reader has to create their own cheat-sheet from their understanding of Git and GitHub. They can visit the previous blogs for reference and create their own version of their cheat-sheet.
What is the need? Creating our own Cheat sheet will not only help us revise the concepts, but also it'll make our understanding even more crisp and clear.
Along with that a google form will be given below where you can submit your cheat-sheet link, pdf or doc as you wish. And don't forget to share it on LinkedIn or Twitter for others to learn from it too. So without any further ado, let's begin.
Cheat Sheet
Initialization Commands
Initialize a git repository
git init
Clone a GitHub repo to your local machine
git clone <url>
Connect to remote repository
git remote add origin <branch>
Create a branch
git checkout <branch_name>
Create and move to a new branch
git checkout -p <branch_name>
List all the branches
git branch
Add changes made to a file, also known as staging.
git add <file_in_which_changes_were_made>
Add all changed files in the current directory
git add .
Commit the changes
git commit -m "commit message"
Checking the status.
git status
Pushing changes to the remote repository.
git push origin <branch_name>
Remove a local git repository
rm -rf .git
To configure username to local machine
git config user.name "Github_UserName"
To configure email to local machine
git config user.email "GitHub_email"
To update local branch with the changes made in the remote repo
git pull -r
To get changes from remote repo, but not merge it automatically
git fetch
To merge branches
git merge <branch_name_to_be_merged>
Check logs like commits etc.
git log
To see difference between two commits
git diff <commit1> <commit2>
To save your current changes into stash before committing it, in case need to work on other changes and not want to loose the previous changes.
git stash
Pop out from stash to dev line
git pop
List all the stash
git stash list
To see the contents of a stash
git stash show stash@{n}
Reset a commit
git reset HEAD~n #no of commits from HEAD
Soft reset
git reset --soft HEAD~n
Hard reset
git reset --hard HEAD~n
Revert the changes made in a commit
git revert <commit_hash>
To revert the previous commit
git revert HEAD
To see commit history / logs in a concise format
git log --online
To see logs in a graphical format
git log --graph
Rebase a feature branch onto the latest commit of the main branch
git checkout feature_branch git rebase main_branch
History of changes made to a specific file
git log <file>
Show the commits on branchA that are not on branchB
git log branchA..branchB
Delete file from a project
git rm <file>
Move file from one folder to another
git mv [existing-path] [new-path]
To cherry-pick a commit
git cherry-pick <commit_hash>
To Rename a branch
git checkout -R <old_branch_name> <New_Branch_name>
Conclusion
Here comes the end of My version of cheat sheet and now its your turn. I've summed up 37 commands starting covering all the corners of Git and GitHub, be it the very basics or be it the advanced one. Go through it and curate your own. I hope this will add value to your learnings.
Submit your cheat-sheet here: https://forms.gle/om6wLNB3woy7SKwz7
Ending this with a QUOTE
Embrace the challenges, master the tools, and transform your obstacles into opportunities. With Linux and Git as your allies, there's no limit to what you can achieve in the world of DevOps.
Happy Learning