I am using GitHub desktop and git command line (to basically stash my code when I need to make a commit on another branch). I use git stash save
and save my code. I then update another branch and switch back to my testing branch which i update to master. I then unstash my code with
git stash pop
This is the output after I ran git stash pop:
Auto-merging update_registration.php
CONFLICT (content):
Merge conflict in update_registration.php
The stash entry is kept in case you need it again.
But then I end up with
<<<<<<< Updated upstream
//Code and whatnot
=======
<<<<<<< Updated upstream
>>>>>>> Stashed changes
in my files and it is quite frustrating truing to manage the code and delete all these lines from my code to upload it to the server.
Am I using git stash wrong?
Thanks
What happened was this: You changed a part ("Updated upstream") while your changes were stashed that was also changed in the stashed part ("Stashed changes"). So when restoring the stashed changes, there was a merge conflict.
General advice: Do different things on different branches at different times, or do different things in different workspaces concurrently.
So if you are implementing something on branch A
and you need to do something different on the project, and you have uncommitted changes, you have two choices:
Do it in the same workspace: Then do git stash
saving your uncommitted changes, create a new branch (probably on master
) with git checkout -b <new_branch> master
or checkout an existing branch. Then hack along, committing changes, finally return to your work using git checkout A
and git stash pop
. Changes should apply cleanly then.
Do it in a different workspace: Do git clone
of your repository in a different directory, hacking and comitting there. If you want to continue on the other branch, just change directories.
In any case you'll have to merge branches in the end if you want to integrate your work. The better you organize your work, the more often you will pick option 1 from the list above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With