Day 12 - Git CheetsheetπŸ› οΈπŸ“š

Day 12 - Git CheetsheetπŸ› οΈπŸ“š

Β·

3 min read

Celebrating Achievements and Sharing Knowledge! πŸŽ‰πŸ’‘

Hey DevOps Enthusiasts! πŸ‘‹ Today marks the completion of our Linux & Git-GitHub hands-on journey. πŸš€ I hope you've found it as exciting and enlightening as I have! πŸ™Œ

Cheatsheet: Mastering Git Commands πŸš€

Git Essentials: Your Quick Reference Guide πŸ“–πŸ”—

Installation & GUIs:

Setup:

  • Configure global user information for all local repositories:

      git config --global user.name "[firstname lastname]"
      git config --global user.email "[valid-email]"
      git config --global color.ui auto
    

Setup & Init:

  • Initialize an existing directory as a Git repository:

      git init
    
  • Clone a repository from a hosted location via URL:

      git clone [url]
    

Stage & Snapshot:

  • View modified files in the working directory, staged for the next commit:

      git status
    
  • Add a file to the staging area:

      git add [file]
    
  • Commit your staged content:

      git commit -m "[descriptive message]"
    

Branch & Merge:

  • List branches with an indicator for the active branch:

      git branch
    
  • Create a new branch:

      git branch [branch-name]
    
  • Switch to another branch:

      git checkout [branch]
    
  • Merge the specified branch's history into the current one:

      git merge [branch]
    

Inspect & Compare:

  • Show the commit history for the active branch:

      git log
    
  • Show commits on branchA that are not on branchB:

      git log branchB..branchA
    
  • Show the diff of what is in branchA that is not in branchB:

      git diff branchB...branchA
    

Tracking Path Changes:

  • Delete a file from the project and stage the removal for commit:

      git rm [file]
    
  • Change an existing file path and stage the move:

      git mv [existing-path] [new-path]
    

Ignoring Patterns:

  • Configure system-wide ignore patterns for all local repositories:

      git config --global core.excludesfile [file]
    
  • Create a .gitignore file with desired patterns.

Share & Update:

  • Add a Git URL as an alias:

      git remote add [alias] [url]
    
  • Fetch branches from a remote:

      git fetch [alias]
    
  • Merge a remote branch into the current one:

      git merge [alias]/[branch]
    
  • Transmit local branch commits to the remote repository branch:

      git push [alias] [branch]
    
  • Fetch and merge any commits from the tracking remote branch:

      git pull
    

Rewrite History:

  • Apply commits of the current branch ahead of a specified one:

      git rebase [branch]
    
  • Clear staging area, rewrite working tree from a specified commit:

      git reset --hard [commit]
    

Temporary Commits:

  • Save modified and staged changes:

      git stash
    
  • List stashed file changes:

      git stash list
    
  • Apply changes from the top of the stash stack:

      git stash pop
    
  • Discard changes from the top of the stash stack:

      git stash drop
    

Reflect, Share, and Keep Learning! πŸš€πŸŒŸ

Let's celebrate our achievements, share our knowledge, and continue this incredible DevOps journey! πŸ™ŒπŸ’»

Did you find this article valuable?

Support Nilkanth Mistry by becoming a sponsor. Any amount is appreciated!

Β