Git pull in IntelliJ without modifying change list

140 views Asked by At

I have multiple git changelists in IntelliJ, and now I need to update my local code by doing a git pull from remote. However, I receive an error while doing the git pull which says "Commit/Stash before pulling." I can stash my local code and then pull, but whenever I stash the code, my changelists get merged. Now I need to find a way to overcome this issue. How can I do this in IntelliJ?

enter image description here

Teammate pushed their code to remote, now i need that code in my local setup.
I can't commit my as it doesn't fully developed neither i can't stash , change list will be merged .

Is there a way to do pull without commit or stash ?? or looking for a better solution.

2

There are 2 answers

0
Dino Letic On BEST ANSWER

Also, you can start using Shelves instead of Stashing.

See: https://www.jetbrains.com/help/idea/shelving-and-unshelving-changes.html,

Your changes will be saved as patches and changelogs will be preserved.

0
hlovdal On

I can't commit my as it doesn't fully developed

Yes, you can and should!

You should stop using git stash and instead just check in changes as normal, ordinary commits - although mark them as temporary commits.

TL;DR

Replace git stash push with git commit -am "==== temp ====" and git stash pop with git reset HEAD^ # On the same branch as you did the temp commit above!.


So assuming the branch you are working on is named my_feature_branch and you currently have some in progress changes:

git switch my_feature_branch
git status
git add $...WHATEVER_FILES_ARE_MODIFIED...
git commit -m "==== before pull of teammate's changes ===="
git fetch origin
gitk --all &     # Optional, but lets you inspect what the difference between your
                 # my_feature_branch branch and the new changes from
                 # origin/my_feature_branch.
git rebase origin/my_feature_branch my_feature_branch
# If any conflicts, use https://github.com/hlovdal/git-resolve-conflict-using-kdiff3
git reset HEAD^ # Undo the earlier temporary commit, bringing you back to where you were,
                # but now on top of the newly fetched changes from your teammate.

Checking in things temporary and then change/remove later is not only ok, you are not properly using git if you don't. Beginners in git are sometimes afraid of checking in things, but that is the wrong mindset - you should be afraid of not checking in changes.

(And possibly more often than you currently are, you should never be more than 2 minutes away from checking in and going home).