gitversion-controlgithub

How to pull new files and changes with git without commiting my changes?


Is there a way to use git to pull new files and changes that others have made, without having to commit my changes? I'm fearful that my changes might mess things up..


Solution

  • First of all, you can use git fetch anytime to load the changes from the remote repository without it influencing your working directory or your local branches at all.

    What you probably want is to stash your changes, so you can update your local branch to the newest state, and then continue working on your changes. To do that, use git stash. This will save your changes temporarily and then revert them, so it looks as if you did not do anything (don’t worry, it’s still saved). Then you can just git pull to update your branch and get the newest changes. After that, use git stash pop to unstash your changes, and get them back.

    In some cases, you will run into conflicts when unstashing things, usually when you started editing files that were also changed in the updates from git pull. Those files get the usual conflict markers and you can resolve them locally just as you are used to.