user1940321
user1940321

Reputation:

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..

Upvotes: 11

Views: 16174

Answers (2)

Jiří Pospíšil
Jiří Pospíšil

Reputation: 14402

You can stash (hide) your changes, pull and then apply your changes again:

git stash
git pull
git stash pop # or apply if you want to keep the changes in the stash

Note that if there are any conflicts, git stash pop will fail and you will have to resolve them.

Upvotes: 5

poke
poke

Reputation: 387755

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.

Upvotes: 12

Related Questions