Course lesson

Use `git stash` to Save Local Changes While Pulling

If we make a change to the same function both locally and remotely, then when we try to pull down the remote changes, we'll run into a conflict - and git won't pull the remote changes down.

Duration
4 min
Access
Free
Transcript
Retained from source evidence

If we make a change to the same function both locally and remotely, then when we try to pull down the remote changes, we'll run into a conflict - and git won't pull the remote changes down.

So first, we'll use git stash to stash the local changes, and then git pull to get the remote changes. To apply the stashed changed, we'll then use git stash pop

Since we changed the same function however, we'll get a merge conflict! So we'll fix the merge conflict, and then add and commit that change.

Finally, we'll drop the change from the stash with: git stash drop stash@{0}

Terminal
# Save the local changes,
git stash

# Get remote changes
git pull

# To apply the stashed changed
git stash pop

# You will need to  fix the merge conflict
# Then drop the change from the stash
git stash drop stash@{0}

✏️ Edit on GitHub