I'm in git trouble - really need some help

Last week I created a branch for a feature and merged it locally with master. I did have some issues but everything worked. I merged another branch with my final feature and merged locally to master again but I had some issues. I don’t even know where to begin. I need to know how to get my final version which is on my hamburger-menu branch into my master branch.

My repo is Tarp Configurations. My commit from yesterday was from master before I created my new branch. I had some issues with files in the master branch, I had to fix them but could not switch back to my branch until I committed them - I also pushed them. Basically, I need the changes from my branch to merge into my master but I have a few commits in the way. I did a git revert for my last commit from master but I need to do that I think 3 or 4 more times.

Would someone please help me undo this?

It looks like you have the hamburger-menu branch pushed up to GitHub. Can you just make a Pull Request (hamburger-menu→master (edit: or maybe the other way around? I’m still not 100% sure on what your issue is)) and try to resolve conflicts there if any come up?

You want to get your local hamber-menu branch up to date with your local master? Is that right?

I’m not sure if I’m competent enough to explain what is going on. I guess my branch got pushed after I merged it locally with Master. But I was getting errors - merge conflicts where you get the ====HEAD and >>>> things throughout the file. Here is one of the stupid things I did - I copied the 3 files that had problems while in my branch into a separate project folder. Then I used that code for the corresponding files in Master. But now Master is messed up - my menu changed, my hamburger button doesn’t work, …

Here is what I had in my console (sorry about the F-bombs in my commit messages):


$ git reflog

e40ac45 (HEAD -> master, origin/master) HEAD@{0}: revert: Revert "FUCK"

a52caa8 HEAD@{1}: checkout: moving from hamburger-menu to master

20ce407 (origin/hamburger-menu, hamburger-menu) HEAD@{2}: checkout: moving from master to hamburger-menu

a52caa8 HEAD@{3}: commit: FUCK

a1af2bd HEAD@{4}: checkout: moving from hamburger-menu to master

20ce407 (origin/hamburger-menu, hamburger-menu) HEAD@{5}: checkout: moving from master to hamburger-menu

a1af2bd HEAD@{6}: commit: Fucking local merge

fb522e7 HEAD@{7}: checkout: moving from hamburger-menu to master

20ce407 (origin/hamburger-menu, hamburger-menu) HEAD@{8}: checkout: moving from master to hamburger-menu

fb522e7 HEAD@{9}: commit (merge): Ready to push to Netlify

ef73039 HEAD@{10}: checkout: moving from hamburger-menu to master

20ce407 (origin/hamburger-menu, hamburger-menu) HEAD@{11}: commit: Finished hamburger menu

git log --oneline --graph --all

$ git log --oneline --graph --all
* e40ac45 (HEAD -> master, origin/master) Revert "FUCK"
* a52caa8 FUCK
* a1af2bd Fucking local merge
* fb522e7 Ready to push to Netlify
|\
| * 20ce407 (origin/hamburger-menu, hamburger-menu) Finished hamburger menu
* | ef73039 push before hamburger menu build
* e40ac45 (HEAD -> master, origin/master) Revert "FUCK"
* a52caa8 FUCK
* a1af2bd Fucking local merge
* fb522e7 Ready to push to Netlify
|\
| * 20ce407 (origin/hamburger-menu, hamburger-menu) Finished hamburger menu
* | ef73039 push before hamburger menu build

I tried git pull from master, I did a reset for my last commit. I don’t know what to do. Branch hamburger menu is what I want. How to I get that?

No the reverse. My master was pushed yesterday before I created hamburger-icon. I finished that tonight and did git checkout master followed by git merge hamburger-icon. I would prefer that hamburger-icon branch was master but everything is messed up now. I had to do git add filename for a few files back in master after the merge. I got the merge conflict things …blah-blah-blah. I’m considering running npx create-react-app tarp-project --use-npm again but for a new project folder and then moving everything over somehow.

Can I somehow clone my branch hamburger-menu into a new project folder on my laptop and treat that as my “master” branch in that new folder? Then push that to a new repo on GitHub?

So you believe hamburger-menu has all the changes (or at least most) you want and you want to merge it into master? In other words, you just want to replace master’s code with hamburger-menu’s code?

Yes!

I downloaded that branch, copied it into a new project folder, and am running npm install now but it’s taking FOREVER. Assuming it finishes soon, I’ll run npm start to make sure it’s where I left off, and then I’ll use that new project folder as my project. create-react-app runs quicker so I’m wondering what is causing the slow install.

… just finished…will give updates in a minute. BTW, is merging a branch locally a bad idea? If so, where are the docs for basic/beginner git commands?

I pulled your repo down. What is the last commit made to master that includes most of what you want? You could temporarily checkout that commit off master and then cherry pick all relevant commits on the hamburger-menu branch and then check out this temp branch with the cherry picked commits to a new branch named master-keep. Next, you check out master again and rename to something like master-original using git branch -M master-original. Then, you could check out master-keep and rename it to master and then force push master back to your origin remote. You would still have your original master in master-original if you needed to review it.

Hmm, that is hard to say. My finished version before working on the mobile menu was yesterday right before I created the hamburger-menu branch. I don’t know why merging that branch into master created issues, but I will never merge locally again. I ran npm start but I forgot I did not have my assets folder. Had to stop and restart. I messed up but I do not know what I did wrong - that is what really bothers me. It’s weird how my cloned branch moved into a new folder has a branch name of main. It’s late and I’m going for the brute approach - create a new repo, delete the old. Why does local merges create a problem? Or am I missing something?

Bingo! It worked but it’s a hack solution that works for a self-taught newbie. I thank you and collin for chiming in. I would like to somehow figure out what I did wrong.

It really depends on how you performed the merges. Typically, the local workflow is:

  1. Pull down from master (assumes remote origin master has latest and greatest) and resolve any merge conflicts that might exist.
  2. Checkout a new branch off master.
  3. Make some changes in the new branch.
  4. If everything looks good, then you can check out master, and merge the branch with changes back into master.
  5. Push master back to remote origin.

There are many scenarios that could get your master branch out of sync but you have to handle each on a case-by-case basis.

Wait a minute. FYI, I’m beat and calling it a night. Why would I have to pull anything down if I am creating a new branch after pushing all changes up? Is there something “weird” with local merges that you need to do a git pull after creating the branch, even though the newly created local branch should be a copy of master? Argh! I should have this on Netlify and updating my portfolio, instead I emptied the fridge of cold beers and will pick up in the morning…

I was merely stating the normal workflow if I was starting to work on features of a project. I always push my latest changes up to origin, so when I start the next day, I can simply pull everything down I want to work on. If you are have just branched off master and made some quick changes and you are the only one working on the repo, then sure you do not have to perform that step of pulling down master.

The beauty of git is that I could work on stuff at home, push the changes up to GitHub and go to work and be able to pull those changes down to another computer and make more changes. When I get back home, I could do a git fetch first and compare my local with the remote changes before merging (if I am concerned the ones on the remote are not the most current I want to keep).

Well, that is what I will do in the future but I still don’t understand why a local merge created issues.