4 tips to improve your git skills

Git is a must-know tool for any modern developer and stepping up your skills can only help be more productive.
So here are a few tips to upgrade your git skills.
Efficient switching between branches
Let say you are working between the main branch and the feature-12 branch.
Now, let say you have some uncommitted work one on feature-12 but you need to go back to main. Just stash it!
git stash
you can also add a stash message:
git stash -m "start implementing feature-12"
Now you can checkout main or do whatever you need to. Ready to re-apply changes?
git stash pop
It will re-apply the last stashed changes!
Bonus:
To quickly switch back to the latest used branch:
git checkout -
Reset to the previous state
What happen when you committed and pushed 2 commits and you realized they are complete garbage?
Git reset got your back. Simply:
git reset --hard HEAD~2
and you are back 2 commits behind. To push it:
git push --force-with-lease
Amend commit
What if you just committed your main.py file, but you decided a line was missing from it.
No need to do a new commit, simple amend your last commit:
git commit main.py --amend
Notes: This will prompt you to edit the commit message. If you want to keep the same message, simply do:
git commit main.py --amend --no-edit
Notes:
Using git amend may require to force push the commit. If the push didn't work, simply do:
git push --force-with-lease
Combine add and commit
Here is a quick one. Say you want to create a new commit for your main.py file.
Do:
git commit main.py -m “update main.py”
Instead of:
git add main.pygit commit -m “update main.py”
additional tip:
If you want to push at the same time, simply do:
git commit -m “update main.py” && git push