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

--

--

--

Experience software developer in a quest to democratize software development. More here: https://www.linkedin.com/in/jcdansereau

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Monitoring Application using Elastic APM

Learning to code during the COVID-19 lockdown

A night at the Story Oscars

Develop A Blog Application With Django

🌳 $BRKL is Back: Development Update 🚀

Migrating from PySpark to Snowpark Python Series — Part 1

Python Lesson: Creating loops in Python

C++ “extern”

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jcdan

Jcdan

Experience software developer in a quest to democratize software development. More here: https://www.linkedin.com/in/jcdansereau

More from Medium

SOLID programming principles

How to set up an SFTP server on Rocky Linux 8

Unit Tests using JUnit and Mockito

Inside a machine

A Beginners Guide to Understanding Docker