Day 12: Git & GitHub Cheatsheet

🚀 Aspiring DevOps Engineer | Automation Enthusiast 🤖 🔧 Bridging Dev and Ops to streamline software delivery and boost productivity. 📚 Learning CI/CD, containerization, and infrastructure as code for better software workflows. 💡 Passionate about optimizing processes and reducing manual tasks for top-notch software quality. 🛠️ Exploring DevOps tools: Docker, Kubernetes, Jenkins, Terraform, and more. 🌐 Let's connect, learn, and grow together in the exciting world of DevOps! 🌱
Git Basics:
Initialize a Repository:
git initClone a Repository:
git clone <repository-url>Check Status:
git statusStage Changes:
git add <file> git add . # Stage all changesCommit Changes:
git commit -m "Commit message"View Commit History:
git logCreate a New Branch:
git branch <branch-name>Switch Branches:
git checkout <branch-name>Merge Branches:
git merge <branch-name>Undo Changes (Unstaged):
git checkout -- <file>Undo Changes (Staged):
git reset HEAD <file>Undo Last Commit (Keep Changes):
git reset --soft HEAD~1Undo Last Commit (Discard Changes):
git reset --hard HEAD~1
GitHub Basics:
Push Changes to Remote Repository:
git push origin <branch-name>Pull Changes from Remote Repository:
git pull origin <branch-name>Add Remote Repository:
git remote add origin <repository-url>View Remote Repositories:
git remote -vCreate Pull Request:
Push changes to GitHub.
Go to the repository on GitHub.
Click on "Pull Requests".
Click on "New Pull Request".
Select the branches to compare.
Merge Pull Request:
Go to the Pull Request on GitHub.
Review changes.
Click on "Merge Pull Request".
Confirm merge.
Fetch Changes from Remote:
git fetch originView Branches:
git branch -aRemove Remote Repository:
git remote remove <repository-name>Sync Forked Repository:
Add upstream repository:
git remote add upstream <upstream-repo-url>Fetch changes:
git fetch upstreamMerge changes into local branch:
git merge upstream/<branch-name>
Create and Apply Gitignore:
Create
.gitignorefile in root directory.Add files or patterns to ignore.
Save changes and commit.
View Gitignore Status:
git status --ignored
Advanced Git:
Rebase Branch:
git rebase <base-branch>Interactive Rebase:
git rebase -i <base-branch>Cherry-Pick a Commit:
git cherry-pick <commit-hash>Stash Changes:
git stashApply Stashed Changes:
git stash applyView Stash List:
git stash listDrop Specific Stash:
git stash drop <stash-index>Clean Untracked Files:
git clean -fdView Differences Between Branches:
git diff <source-branch> <target-branch>Resolve Merge Conflicts:
Open the conflicted file.
Manually resolve conflicts.
Add resolved files.
Commit changes.
This cheat sheet covers essential Git and GitHub commands for beginners and more advanced users. Use it as a quick reference guide to streamline your workflow and collaboration processes.
"Fuel my passion and support my journey by clicking 'Buy me a coffee' today!"
~Dipen : )






