Day 12 - Cheat-Sheet

Day 12 - Cheat-Sheet

ยท

4 min read

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

  1. Initialize a git repository

     git init
    
  2. Clone a GitHub repo to your local machine

     git clone <url>
    
  3. Connect to remote repository

     git remote add origin <branch>
    
  4. Create a branch

     git checkout <branch_name>
    
  5. Create and move to a new branch

     git checkout -p <branch_name>
    
  6. List all the branches

     git branch
    
  7. Add changes made to a file, also known as staging.

     git add <file_in_which_changes_were_made>
    
  8. Add all changed files in the current directory

     git add .
    
  9. Commit the changes

     git commit -m "commit message"
    
  10. Checking the status.

    git status
    
  11. Pushing changes to the remote repository.

    git push origin <branch_name>
    
  12. Remove a local git repository

    rm -rf .git
    
  13. To configure username to local machine

    git config user.name "Github_UserName"
    
  14. To configure email to local machine

    git config user.email "GitHub_email"
    
  15. To update local branch with the changes made in the remote repo

    git pull -r
    
  16. To get changes from remote repo, but not merge it automatically

    git fetch
    
  17. To merge branches

    git merge <branch_name_to_be_merged>
    
  18. Check logs like commits etc.

    git log
    
  19. To see difference between two commits

    git diff <commit1> <commit2>
    
  20. 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
    
  21. Pop out from stash to dev line

    git pop
    
  22. List all the stash

    git stash list
    
  23. To see the contents of a stash

    git stash show stash@{n}
    
  24. Reset a commit

    git reset HEAD~n #no of commits from HEAD
    
  25. Soft reset

    git reset --soft HEAD~n
    
  26. Hard reset

    git reset --hard HEAD~n
    
  27. Revert the changes made in a commit

    git revert <commit_hash>
    
  28. To revert the previous commit

    git revert HEAD
    
  29. To see commit history / logs in a concise format

    git log --online
    
  30. To see logs in a graphical format

    git log --graph
    
  31. Rebase a feature branch onto the latest commit of the main branch

    git checkout feature_branch
    git rebase main_branch
    
  32. History of changes made to a specific file

    git log <file>
    
  33. Show the commits on branchA that are not on branchB

    git log branchA..branchB
    
  34. Delete file from a project

    git rm <file>
    
  35. Move file from one folder to another

    git mv [existing-path] [new-path]
    
  36. To cherry-pick a commit

    git cherry-pick <commit_hash>
    
  37. 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

Did you find this article valuable?

Support DevOps with Aakash by becoming a sponsor. Any amount is appreciated!

ย