Cookie Consent by Free Privacy Policy Generator ๐Ÿ“Œ 10 Git stash commands every developer should know

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š 10 Git stash commands every developer should know


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

Git Stash is an extremely useful tool for developers. Learn the usage of the git stash commands to become a productive developer.

Developers are agile. Their work environments are also rapid and fast-moving to keep them on their toes most of the time. I can imagine a situation like this would be quite normal at your workplace:

You are working on a feature and, in between, making some changes that are still too unstable to commit. Now, your boss(they say the boss is always right!) comes over with a rush and informs you that a valued customer is facing the deadliest issue in production. You must take care of it RIGHT NOW.

You don't want to commit unstable changes to your current branch, but you have to switch to another branch and fix the issue to make your customer(and, of course, the boss) happy. However, git doesn't allow you to switch branches without your current changes for the tracked files being committed to the current branch. Wow, what a chicken and egg problem!

Chicken-Egg Problem

Don't worry, we have git stash to rescue.

Welcome to Git stash

The word stash means storing something safely in a hidden and secret place. In the world of git, it tracks your files and folders for changes for everyone's visibility, and with git stash, it also provides a way to secretly put some changes that are only known to you so that you can hide them and again bring them back when required.

The git stash command allows you to save the uncommitted changes locally, switch the branch to do other things, and return to your unfinished work along with the stashed changes. The workflow goes like this:

  • You are in branch feature/A-branch where you have uncommitted changes

  • You stash the changes.

  • You then switch to another branch feature/B-branch to finish the work. You commit(and push) the changes.

  • You switched back to the feature/A-branch branch, applied your stashed changes, and continued your work.

The command that you use to stash your changes is:

git stash

We will learn the usages for 10 commands related to the git stash in this article. If you are a beginner to git and want to know its fundamentals along with frequently used commands, here is a read for you:

Top 10 Git Commands Every Developer Should Know

โœ… Stash your changes

You can have two types of uncommitted changes.

  • The staged changes that git is tracking. It means you have used the git add command to stage them but haven't committed them yet using the git commit command.

  • The unstaged changes that git is not tracking. It is a file that you haven't staged using the git add command.

Use the following command to stash a staged change:

git stash 

# You can also use `git stash save <description>` command to 
# save a stash with a description.

It will create a stash in the stack with a unique reference ID.

git stash

If you want to stash an unstaged change, use the -u switch

git stash -u

Now, it will add one more entry to the stash stack.

stash untracked

You can use the git stash -a command to stash all the files, including the hidden files.

โœ… List all the stashes

You can list all the stashes from the stash stack using this command:

git stash list

It will list all the stashes in a stack, meaning the latest stash will be at the top. Also, notice the format of the stash reference IDs. They are in the format stash@{0}. The number in the curly braces shows their position in the stash stack, 0 being the top.

list stash

โœ… Create a stash without a reference log entry

So far, we have created all the stashes with a reference ID. We have seen the git stash list command show them in the reflog. However, you can create a stash without logging it's reference to the stash reflog.

To do that, use the create command:

git stash create "valid stash"

It will create a stash with a description and unique ID, but nothing will be stored anywhere in the ref namespace. This stash creation method is mostly used for scripts.

without reflog

To add this stash entry into the reflog later, you can use the git stash store command like this:

git stash store -m "adding to reflog" "98c7181a7a3621139a4899be71e93ec7ceb18afa"

The output,

with reflog

โœ… Show the latest stash information

Use the git stash show command to see the information of the latest stash in the stack. By default, it shows the status information of the file stashed and the number of insertions and deletions in the files.

latest stash info

If you want to see a verbose stash output, you can use the -p switch with the above command to see the stash information in the patch view.

git stash show -p

The output,

stash info output

The patch view shows the exact diff between the commits.

โœ… Show the information of a particular stash

What if you want to see the information of a particular stash? Remember the stash reference ID? We can refer to a specific stash and get its information using the show command we learned above.

git stash show shash@{2} -p

Here, we are interested in seeing the information on the third stash in the stack. The output,

info of a particular stash

โœ… Apply and remove a stash

The stashes stay in the stash stack. You can pop(take out) a stash from the stack and apply it to the current branch. Use the following command to pop a stash:

git stash pop

It will pop the latest stash(one at the top of the stack) and apply it to the current branch. Also, the applied stash will be dropped(removed) from the stash stack.

pop stash

โœ… Apply a stash without removing it

What if you want to apply a stash without dropping it from the stack? You can use the following command for that:

git stash apply

The apply command will apply the latest stash from the stack without removing it from the stack.

apply stash

Also, if you want to apply a specific stash from the stack, you can use the stash reference ID like this:

git stash apply stash@{2}

โœ… Remove a stash without applying it

You can also drop the latest stash from the stack without applying it. To do that, use the following command:

git stash drop

You can also drop a specific stash without applying it using the reference ID of the stash:

git stash drop stash@{3}

โœ… Clear all the stash

Sometimes, you may not need the stashes and want to clear them all. Use this command to clear all the stashes from the stack:

git stash clear

โœ… Create a new branch from the stash

You can create a branch from the commits in the stash using the following command:

git stash branch fix/resolve-conflicts-checkout stash@{0}

The command will create a new branch and switch to the new branch.

create branch

You can check the newly created branch using the git branch command.

branch list

That's all for now. Do you know any other usages of the git stash command? Please feel free to comment and let us know.

Thanks for reading it. I hope it was insightful and helped you get familiar with some new git commands. If you liked the article, please post likes/comments and share it in your circles.

Let's connect. You can follow me on Dev, and I also share content on these platforms:

...



๐Ÿ“Œ 10 Git stash commands every developer should know


๐Ÿ“ˆ 71.62 Punkte

๐Ÿ“Œ 10 Git stash commands every developer should know


๐Ÿ“ˆ 71.62 Punkte

๐Ÿ“Œ Top 11 Git Commands That Every Developer Should Know


๐Ÿ“ˆ 51.99 Punkte

๐Ÿ“Œ Git: the basic commands every developer should know


๐Ÿ“ˆ 51.99 Punkte

๐Ÿ“Œ How to Git stash Pop Specific Stash


๐Ÿ“ˆ 48.8 Punkte

๐Ÿ“Œ Git Commands you Should Know if you Plan to Work with Git.


๐Ÿ“ˆ 44.6 Punkte

๐Ÿ“Œ 40 Essential Linux Commands That Every Developer Should Know


๐Ÿ“ˆ 42.45 Punkte

๐Ÿ“Œ SQL Commands that every Developer should know


๐Ÿ“ˆ 42.45 Punkte

๐Ÿ“Œ 40 Essential Linux Commands That Every DEVELOPER Should Know


๐Ÿ“ˆ 42.45 Punkte

๐Ÿ“Œ An Introduction to Git: The Basics Every Beginning Developer Should Know


๐Ÿ“ˆ 40.45 Punkte

๐Ÿ“Œ An Introduction to Git: The Basics Every Beginning Developer Should Know


๐Ÿ“ˆ 40.45 Punkte

๐Ÿ“Œ Git Stash: Der nรผtzliche Zwischenspeicher in Git


๐Ÿ“ˆ 38.71 Punkte

๐Ÿ“Œ git-stash Command in Git | Explained


๐Ÿ“ˆ 38.71 Punkte

๐Ÿ“Œ Important Git Commands which every developer needs in his day to day life


๐Ÿ“ˆ 38 Punkte

๐Ÿ“Œ 13 Basic Linux Commands Every Beginner should know


๐Ÿ“ˆ 35.08 Punkte

๐Ÿ“Œ 7 Linux networking commands that every sysadmin should know | Enable Sysadmin


๐Ÿ“ˆ 35.08 Punkte

๐Ÿ“Œ 31 Linux Commands Every Ubuntu User Should Know


๐Ÿ“ˆ 35.08 Punkte

๐Ÿ“Œ Terminal Commands that Every Developers Should Know


๐Ÿ“ˆ 35.08 Punkte

๐Ÿ“Œ 10 nmap commands every Linux user should know


๐Ÿ“ˆ 35.08 Punkte

๐Ÿ“Œ Windows Defender Commands Every Windows 10 Power User Should Know


๐Ÿ“ˆ 35.08 Punkte

๐Ÿ“Œ 5 Git commands you should know ๐Ÿš€


๐Ÿ“ˆ 35.06 Punkte

๐Ÿ“Œ Git Cheat Sheet - 40+ Git Comands You Should Know


๐Ÿ“ˆ 33.06 Punkte

๐Ÿ“Œ Five Azure services every developer should know


๐Ÿ“ˆ 30.91 Punkte

๐Ÿ“Œ Things Every Developer Should Know About Security - Chris Romeo - ASW #124


๐Ÿ“ˆ 30.91 Punkte

๐Ÿ“Œ Ten skills every web developer should know in 2021 and beyond


๐Ÿ“ˆ 30.91 Punkte

๐Ÿ“Œ Visual Studio Live! - Choose Azure SQL Database and Learn What Every Developer Should Know


๐Ÿ“ˆ 30.91 Punkte

๐Ÿ“Œ Optimistic vs Pessimistic Concurrency: What Every Developer Should Know


๐Ÿ“ˆ 30.91 Punkte

๐Ÿ“Œ 8 Design Principles that every Ruby Developer should know


๐Ÿ“ˆ 30.91 Punkte

๐Ÿ“Œ 5 building blocks of blockchain every developer should know


๐Ÿ“ˆ 30.91 Punkte

๐Ÿ“Œ 5 Python Tricks Every Python Developer should know


๐Ÿ“ˆ 30.91 Punkte

๐Ÿ“Œ Top 10 Python Packages Every Developer Should Know About


๐Ÿ“ˆ 30.91 Punkte

๐Ÿ“Œ 100 Vital VS Code Shortcuts Every Developer Should Know.


๐Ÿ“ˆ 30.91 Punkte

๐Ÿ“Œ Top 10 AI Tools Every Developer Should Know About


๐Ÿ“ˆ 30.91 Punkte

๐Ÿ“Œ Top 5 Windows and Microsoft Store Trends Every Developer Should Know


๐Ÿ“ˆ 30.91 Punkte

๐Ÿ“Œ 12 Powerful WordPress Hooks Every Developer Should Know


๐Ÿ“ˆ 30.91 Punkte











matomo