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:
git init: Initialize a new Git repository in the current directory.
- Usage:
git init
- Usage:
git clone: Copy an existing repository from a remote source to your local machine.
- Usage:
git clone <repository_url>
- Usage:
git add: Stage changes to be committed in the next commit.
- Usage:
git add <file(s)>
- Usage:
git commit: Create a new commit with the staged changes.
- Usage:
git commit -m "Commit message"
- Usage:
git status: View the status of your working directory and staged changes.
- Usage:
git status
- Usage:
git log: View the commit history in reverse chronological order.
- Usage:
git log
- Usage:
git diff: Show the differences between your working directory and the last commit.
- Usage:
git diff
- Usage:
Branching and Merging:
git branch: List all branches in the repository or create a new branch.
- Usage:
git branch
(list branches) orgit branch <branch_name>
(create branch)
- Usage:
git checkout: Switch between branches or restore files from a specific commit.
- Usage:
git checkout <branch_name>
(switch branch) orgit checkout <commit_hash> <file(s)>
(restore files)
- Usage:
git merge: Merge changes from one branch into the current branch.
- Usage:
git merge <branch_name>
- Usage:
git rebase: Reapply commits from one branch on top of another branch.
- Usage:
git rebase <branch_name>
- Usage:
Collaborating with GitHub:
git remote: Manage remote repositories linked to your local repository.
- Usage:
git remote add <name> <repository_url>
(add remote) orgit remote -v
(view remotes)
- Usage:
git push: Upload local commits to a remote repository.
- Usage:
git push <remote_name> <branch_name>
- Usage:
git pull: Fetch and integrate changes from a remote repository into the current branch.
- Usage:
git pull <remote_name> <branch_name>
- Usage:
git fork: Create a personal copy (fork) of a remote repository on GitHub.
- Usage: Click the "Fork" button on the repository page.
git pull request: Propose changes to the original repository through a pull request.
- Usage: Create a new pull request on GitHub.
Undoing Changes:
git reset: Unstaged changes, move HEAD, or undo commits.
- Usage:
git reset <file(s)>
(unstaged changes) orgit reset --hard <commit_hash>
(undo commits)
- Usage:
git revert: Create a new commit that undoes the changes made by a specific commit.
- Usage:
git revert <commit_hash>
- Usage:
Miscellaneous:
git config: Configure Git settings, such as username and email.
- Usage:
git config --global
user.name
"Your Name"
andgit config --global
user.email
"
youremail@example.com
"
- Usage:
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.
- Usage: Create a
💡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 🌈