Git Cheat Sheet

π Passionate DevOps Engineer | AWS Enthusiast | Continuous Learner π
π Hello! I'm Paresh Parde, a passionate and eager DevOps enthusiast ready to embark on a journey in the world of technology. With a solid foundation in both development and operations, I bring a fresh perspective and a hunger to learn and grow within the DevOps landscape.
Let's connect and explore how we can create impactful solutions together!π
Follow me on LinkedIn: https://www.linkedin.com/in/paresh-parde-544493232/
Introduction π
Welcome to the ultimate Git cheat sheet! Whether you're new to version control or a seasoned developer, this guide will help you navigate Git's powerful commands and features. Let's dive in and make your Git workflow more efficient and enjoyable!
Setting Up Git π οΈ
Install Git
Windows: Download and install from
git-scm.com.macOS: Use Homebrew:
brew install git.Linux: Use your package manager, e.g.,
sudo apt-get install git (Debian/Ubuntu).Configure Git
Set your name:
git config --global user.name "Your Name"Set your email:
git config --global user.email "your.email@example.com"Check your configuration:
git config --list
Basic Commands π
Initialize a Repository
Start a new repository:
git initClone a Repository
Copy an existing repository:
git clone https://github.com/user/repo.gitCheck Status
See the current status of your working directory:
git status
Working with Changes π
Add Changes
Stage changes:
git add filenameStage all changes:
git add .Commit Changes
Commit staged changes:
git commit -m "Your commit message"View Commit History
Show commit history:
git log
Branching and Merging πΏ
Create a New Branch
Create a branch:
git branch new-branchSwitch to a branch:
git checkout new-branchCreate and switch to a new branch:
git checkout -b new-branchMerge Branches
Merge a branch into your current branch:
git merge branch-nameDelete a Branch
Delete a branch:
git branch -d branch-name
Remote Repositories π
Add a Remote
Add a new remote:
git remote add origin https://github.com/user/repo.gitView Remotes
List configured remotes:
git remote -vPush Changes
Push to a remote repository:
git push origin branch-namePull Changes
Pull from a remote repository:
git pull origin branch-name
Stashing Changes ποΈ
Save Changes Temporarily
Stash changes:
git stashApply Stashed Changes
Apply the latest stash:
git stash applyView Stashes
List stashed changes:
git stash list
Rebasing and Resetting π
Rebase Branch
Rebase your current branch onto another branch:
git rebase branch-nameReset Changes
Reset your working directory:
git reset --hardUnstage Changes
Unstage a file:
git reset filename
Advanced Commands βοΈ
Cherry-Pick Commits
Apply a specific commit from one branch to another:
git cherry-pick commit-hashRevert Commits
Create a new commit that undoes a previous commit:
git revert commit-hashShow Differences
Show changes between commits, branches, etc.:
git diff
Helpful Tips & Tricks π‘
Aliasing Commands
Create shortcuts for commonly used commands:
git config --global alias.co checkoutViewing File History
See the history of a specific file:
git log -- filenameIgnoring Files
Create a file to specify files and directories Git should ignore.
.gitignore
Conclusion π
With this cheat sheet, you're now equipped to handle Git like a pro! From basic commands to advanced operations, Git offers powerful tools to manage your code efficiently. Keep this guide handy, and happy coding!
πHappy Learning:)



