The following is a very common error message encountered when we try to pull a git repository locally with some existing local changes in the local repository.
Please commit your changes or stash them before you merge. Aborting
I have a question about stdcall's answer in this post.
He has mentioned the following 3 options over there.
Question:
If I just commit my local changes using the command git commit -m "Saving my local changes"
Is git pull
not going to throw the same error that I have mentioned above? I mean I don't need to do a merge (using git merge
) or anything while pushing to gitlab?
In a normal workflow when I don't see any error, I follow the steps below to commit and push my changes:
- git add .
- git commit -m "My message"
- git push
Since I am getting above error, are the following steps correct:
- git commit -m "Saving my local changes'
- git pull // This will pull whatever is on the branch including my local changes
- git push //This will push my local changes to git
I have used git stash
in the past and it has resulted in my local changes getting wiped out so I am scared of using it. I didn't do git stash pop though and probably that's the reason it behaved like that.