Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Switching to the previous Git branch... duh!
Edwin Torres
Edwin Torres

Posted on • Edited on

     

Switching to the previous Git branch... duh!

I have been usingGit version control for several years. I probably should have mastered it by now, but that has not happened. I know just enough commands and options to bedangerous. Every now and then, I will learn something new and smile.

One example is thegit checkout command. I have used this command countless times to switch back and forth between different branches in my Git repos. For example, here is a repo withmaster anddevelop branches:

$ git checkout developSwitched to branch'develop'$ git checkout masterSwitched to branch'master'Your branch is up todatewith'origin/master'.$ git checkout developSwitched to branch'develop'$
Enter fullscreen modeExit fullscreen mode

I have been switching Git branches this way foryears. But this week, I learnedgit checkout -. This version of the command switches to thelast branch that you were on:

$ git checkout developSwitched to branch'develop'$ git checkout -Switched to branch'master'Your branch is up todatewith'origin/master'.$ git checkout -Switched to branch'develop'$ git checkout -Switched to branch'master'Your branch is up todatewith'origin/master'.$
Enter fullscreen modeExit fullscreen mode

Mind blown! Thegit checkout - command is a blessing. It is so much easier, especially when your Git branches have long names. This would have saved me lots of typing over the years 😩. Oh well, better late than never!

If you already know aboutgit checkout -, great. If not, I hope it makes your Git life easier.

Thanks for reading. 😃

Follow me on Twitter@realEdwinTorres for more programming tips and help.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Department Chief Engineer @MITREcorp. CS professor @monmouthu. Proud husband and father ❤️. My tweets are my own.
  • Location
    NJ
  • Education
    Doctor of Engineering, George Washington University
  • Work
    Principal Software Engineer at MITRE
  • Joined

More fromEdwin Torres

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp