How to transfer new files and changes using git without making changes?

Is there a way to use git to pull out new files and changes that others made without the need to make changes? I am afraid that my changes may ruin things.

+6
source share
2 answers

First of all, you can use git fetch at any time to download changes from a remote repository without affecting your working directory or your local branches at all.

What you probably want is to save your changes in order to update the local branch to the latest state, and then continue to work on your changes. To do this, use git stash . This will temporarily save your changes and then revert them, so it looks like you didn’t do anything (don’t worry, it is still saved). Then you can just git pull update the branch and get the latest changes. After that, use git stash pop to unlock your changes and revert them.

In some cases, you will encounter conflicts during unstable operation, usually when starting editing files that have also been changed in updates from git pull . These files get regular conflict markers, and you can resolve them locally just like you used to.

+8
source

You can hide (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 

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

+3
source

All Articles