Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»GIT»How to Git Stash Changes

    How to Git Stash Changes

    By RahulOctober 29, 20213 Mins Read

    Ever had a need to temporarily store changes that you made to your code? Without committing it? For example, you were in the middle of branch editing and someone asked you to collaborate on a different one? If you didn’t, you most likely will somewhere down the road in your developer career. At that point, it will be extremely useful to know how to use git stash. With the help of that command, you can temporarily store your current work to jump onto something else. Read on and find out how to Git stash changes.

    Advertisement

    How to Use Git Stash Command to Temporarily Save Your Changes

    Okay, so picture this scenario. You are currently working on a piece of code that should bring a new feature to the application. All of a sudden, you urgently have to assist one of your co-workers with a bug that they found in a completely different branch. The first thing that you would want to do is to check which files you recently modified in the branch on which you are currently working. You can do that with a simple command.

    git status 
    

    This command will show you modified files. Below, you can find an example of the output.

    Output:
    modified: app_layer.php modified: readme.txt modified: functions.php

    Of course that you don’t want to lose your work on these files, but on the other hand you can’t just commit them. And that is where git stash shines!

    The command itself is extremely easy and straightforward. An example is below.

    git stash 
    

    The output will look similar to the one below.

    Output:
    Saved working directory and index state WIP on master: 3tjaq12w Implement the new login box HEAD is now at 3tjaq12w Implement the new login box

    And that’s it! All your work on the current branch is saved in some sort of clipboard. Feel free to start working on whatever popped up in the meantime.

    Speaking of pop, here’s how you can return to the place where you left off once you are ready to continue. Simply type this into your terminal.

    git stash pop 
    

    After the command above, you will be returned to your last saved state.

    Conclusion

    You’ll agree with us when we say that this is a very simple Git command to learn and it is of real value to having knowledge of it. We certainly hope that you’ll find a good use for what you learned today. Remember, developing is a never-ending course when it comes to learning.

    git stash
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Git Change Remote URL: How to

    Git Change Remote URL in Local Repository

    Git Change Remote URL to SSH (from HTTPS)

    How to Create Branch in Git Repository

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • 20 Basic Linux Commands for the Beginners (Recommended)
    • tail Command in Linux with Examples
    • What is a Orphan Process in Unix/Linux
    • How To Display Warning Message to Unauthorized SSH Access
    • How to Set a Custom SSH Login Banner and MOTD
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.