Git is an essential tool for developers, but it can feel a bit overwhelming with all its commands. Fear not! Here's a simplified guide to the most important Git commands, explained in straightforward terms. Also read till last to make your git commands easier by using alias. Let’s dive in and git you up to speed!
1. git pull
Think of git pull
as grabbing the latest version of a document from a shared folder. It pulls all the latest changes from the remote repository (the shared folder) into your local copy (your personal document).
Shortcut Idea: gp
for git pull origin main
2. git push
Finished making changes? git push
sends your updates back to the remote repository so everyone can see your work. It's like uploading your edited document back to the shared folder.
Shortcut Idea: gps
for git push origin main
3. git fetch
git fetch
is like checking the shared folder for any new updates without changing your current document. It lets you see what’s new before you decide to merge those changes into your work.
Shortcut Idea: gf
for git fetch origin main
4. git merge
When you’re ready to combine changes, git merge
does the job. It’s like merging two versions of a document into one, keeping all the good stuff from both.
Shortcut Idea: gm
for git merge
5. git stash
In the middle of editing but need to switch tasks? git stash
temporarily saves your changes so you can come back to them later, without committing them yet.
Shortcut Idea: gs
for git stash
6. git stash list
Want to see what you've saved? git stash list
shows all the work you've temporarily set aside, so you can pick up where you left off.
Shortcut Idea: gsl
for git stash list
7. git stash pop
Ready to continue where you left off? git stash pop
restores your stashed changes and removes them from the stash list.
Shortcut Idea: gsp
for git stash pop
8. git stash drop
Don’t need those saved changes anymore? git stash drop
deletes a stash entry, freeing up space for new work.
Shortcut Idea: gsd
for git stash drop
9. git cherry-pick
If you need to bring a specific change from another branch into your current branch, git cherry-pick
lets you do just that. It’s like copying a paragraph from one document into another.
Shortcut Idea: gcp
for git cherry-pick <commit>
10. git checkout
git checkout
is like switching between different versions of a document or different branches of your project. It lets you move to a different version or branch to see or work on something else.
Shortcut Idea: gco
for git checkout
11. git switch
git switch
is a simpler command for changing branches. It’s the same as git checkout
, but specifically for moving between branches.
Shortcut Idea: gsw
for git switch
Tip: Customize Your Git Workflow with Aliases
You can save time by creating aliases for your most-used Git commands. Here's how to set them up:
git config --global alias.gp "pull origin main"
git config --global alias.gps "push origin main"
git config --global alias.gsp "stash pop"
git config --global alias.gco "checkout"
With these shortcuts, your Git workflow will be quicker and smoother. No need to type out the full commands every time—you’ve got your personal set of tools ready to go.
Git doesn't have to be complicated. With these commands, you'll be managing your code like a pro in no time. Happy coding!