Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When I use git stash I end up with <<<<<<< Updated upstream and other things in my files

Tags:

git

merge

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

like image 549
StormsEngineering Avatar asked Mar 26 '19 22:03

StormsEngineering


1 Answers

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:

  1. 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.

  2. 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.

like image 103
U. Windl Avatar answered Sep 20 '22 04:09

U. Windl