DEV Community

Cover image for How to keep your local changes while pulling the code
Saumya Agnihotri
Saumya Agnihotri

Posted on

How to keep your local changes while pulling the code

If you are working on a project in a team and you have used GitHub as your version control system then you might have come across a situation where you're working on some feature but the work hasn't finished yet and there are some update from other member and now you need to pull the code again from remote repository.

Now a problem arises here, while you're pulling the code your changes (work in progress) will be overridden and you will lose your code that wasn't committed. So in such scenarios, you can use a git command known as git stash.

What is Git Stash?

Git stash will solve the problem faced in the above scenario. You can keep your changes similar to keeping a draft and then after pulling the remote repo code you can go back to draft version and apply the changes again.

So the usual flow will go like this :

  1. You are working on some unfinished feature and you need to save this (draft)

              git stash
               or 
              git stash save "feature X"
    
  2. Now you pull the code

              git pull origin master
    
  3. Restore the work you were doing for feature X using below command

              git stash apply
    

That's it. You are done ✅

For learning more about git stash you can refer to these resources :

Links -

Top comments (0)