Day-12: Git & GitHub Cheatsheet day

Day-12 of 90 Days of DevOps Challenge

Day-12: Git & GitHub Cheatsheet day

Introduction🎉

Hey there, fellow DevOps enthusiasts! 🖐️

If you're anything like me, you know how crucial Git and GitHub are to our daily development workflows. These tools might seem intimidating at first, but fear not! 🤖 I'm here to demystify them and provide you with a handy cheat sheet to level up your Git game. Let's get started! 🚀

🚀Git & GitHub Cheat Sheet! 🚀

Git Basics:

  1. git init: Initialize a new Git repository in the current directory.

    • Usage: git init
  2. git clone: Copy an existing repository from a remote source to your local machine.

    • Usage: git clone <repository_url>
  3. git add: Stage changes to be committed in the next commit.

    • Usage: git add <file(s)>
  4. git commit: Create a new commit with the staged changes.

    • Usage: git commit -m "Commit message"
  5. git status: View the status of your working directory and staged changes.

    • Usage: git status
  6. git log: View the commit history in reverse chronological order.

    • Usage: git log
  7. git diff: Show the differences between your working directory and the last commit.

    • Usage: git diff

Branching and Merging:

  1. git branch: List all branches in the repository or create a new branch.

    • Usage: git branch (list branches) or git branch <branch_name> (create branch)
  2. git checkout: Switch between branches or restore files from a specific commit.

    • Usage: git checkout <branch_name> (switch branch) or git checkout <commit_hash> <file(s)> (restore files)
  3. git merge: Merge changes from one branch into the current branch.

    • Usage: git merge <branch_name>
  4. git rebase: Reapply commits from one branch on top of another branch.

    • Usage: git rebase <branch_name>

Collaborating with GitHub:

  1. git remote: Manage remote repositories linked to your local repository.

    • Usage: git remote add <name> <repository_url> (add remote) or git remote -v (view remotes)
  2. git push: Upload local commits to a remote repository.

    • Usage: git push <remote_name> <branch_name>
  3. git pull: Fetch and integrate changes from a remote repository into the current branch.

    • Usage: git pull <remote_name> <branch_name>
  4. git fork: Create a personal copy (fork) of a remote repository on GitHub.

    • Usage: Click the "Fork" button on the repository page.
  5. git pull request: Propose changes to the original repository through a pull request.

    • Usage: Create a new pull request on GitHub.

Undoing Changes:

  1. git reset: Unstaged changes, move HEAD, or undo commits.

    • Usage: git reset <file(s)> (unstaged changes) or git reset --hard <commit_hash> (undo commits)
  2. git revert: Create a new commit that undoes the changes made by a specific commit.

    • Usage: git revert <commit_hash>

Miscellaneous:

  1. git config: Configure Git settings, such as username and email.

  2. gitignore: Create a .gitignore file to specify files and directories to be ignored by Git.

    • Usage: Create a .gitignore file in the root of your repository and list files/directories to ignore.

💡Pro Tips:

  • Always write clear and concise commit messages.

  • Use branches for new features and bug fixes to keep the main branch clean.

  • Review pull requests thoroughly to maintain code quality.

  • Regularly update your local repository with git pull to avoid merge conflicts.

  • Back up your important work on remote repositories like GitHub.

There you have it, your handy cheat sheet for mastering Git and GitHub commands!

I hope this helps you navigate the world of version control and collaboration with confidence and ease. Remember, practice makes perfect, so keep experimenting and learning! Happy coding!

Feel free to share this cheat sheet with your DevOps friends, and if you have any questions or feedback, reach out to me anytime. Keep the passion for DevOps alive!

Signing off,

Your Friendly DevOps Demystifier 🌈