(master) git pull origin //get most up to date remote (master) git checkout -b mybranch (mybranch) do some work without committing (mybranch) git checkout master (master) git pull origin //to get updated remote to merge locally // pull aborted because I accidentally changed a line in (master) // before switching to (mybranch) (master) git stash //to disregard the accidental change (master) git pull origin // pull successful (master) git checkout mybranch (mybranch) all my uncommited changes are gone???
mybranch now sits at its last commit. There are a few files that were added by
git add . that are showing up but there is about 100 lines of code not showing up on the file system.
Is this really what happens when you checkout a different branch without committing? or does
git stash stash all uncommited changes regardless of branch? Either way if anyone knows where my progress went I will be eternally grateful.
This is my normal workflow. I will explain my current understanding of each step. I was not formally taught how to use git with a team, so I would be thrilled to learn a proper workflow. anyway:
(master) git pull origin
I do this to get the most up to date version from github.
(master) git checkout -b mybranch
This creates a new branch that matches master and the online repo.
(mybranch) git add . //only if I added files (mybranch) git commit -a
This is me doing all my work. When I get something working correctly, I commit. I repeat this process until I am through working or reach a major checkpoint
(mybranch) git checkout master
switch back to master
(master) git pull origin
if nobody has pushed to the online repo since my first pull, I receive a message saying nothing to pull, otherwise it pulls the updated code to master
(master) git merge mybranch
if there was nothing to pull, this is a FF merge and all is well. If there was an update, here is where I deal with any merge conflicts.
(master) git commit -a
if there were merge conflicts, I make my merge commit. This is only done after all conflicts are handled the code runs without issues
(master) git push -u origin master
update the repository with my code
Like I said I am new to git, so if this workflow is flawed please point it out. Also, if my explanation points to any fundamental misunderstandings, I would appreciate some kind worded educating as well. Gracias to all.
P.S. This is a small group and I prefer to handle all merge commits myself.