Deploying test website using Git subtree

I've been attempting to work with Git for some time now, and invariably I end up overwhelmingly confused. I'm in the middle of a project now which, when it started, had both myself and a programmer I hired to help me. Long story short, he is no longer with us, and I'm up Git's Creek, sans paddle.

I'm trying to deploy a test version of an angular website to the hosting server using Git, pushing the dist folder to Dreamhost as a subtree.

I've successully done this in the past (once), using the process outlined for me by the aforementioned programmer:

Via shell, create a bare remote repo in its own directory at Dreamhost:
$ mkdir website.git$ cd website.git$ git init --bare

Set up a post-receive hook in a new file in its own .git folder, with content of said file like so:
#!/bin/sh GIT_WORK_TREE=~/[MY DOMAIN HERE] git checkout -f

Add the Dreamhost Git repo as a remote:
git remote add dreamhost ssh://USERNAME@DOMAIN/~/website.git

From the branch I want to push "live," use this command:
git subtree push --prefix dist/ dreamhost master

Open in new window


Following this process, I was able to deploy the /dist folder as a test version of the site (several months ago – this is a project I can work on only as time is available, making it challenging to retain the things I've learned). Worked like a charm.

This time around – with things already set up from before on the hosting end – not so much. Now, I get the following error(s):

 ! [rejected]        3a952c188efdeb7d26753953acbe4fbdde6e69cf -> master (non-fast-forward)
error: failed to push some refs to 'ssh://user@website.com/~/website.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

Open in new window


At this point I'm barely holding on to what little comprehension I have. I guessed I needed to to fetch and merge from the Dreamhost git repo, like so:

git fetch dreamhost

Open in new window

git merge dreamhost/master

Open in new window


This appeared to have done things... a lot of things. Ao I tried to push the subtree again:

git subtree push --prefix dist/ dreamhost master

Open in new window


...and still got the non-fast forward error.

At this point I realize I may have made a huge mistake, since I just went and merged a subtree into my branch. Never one to let ignorance stop me from plowing forward, I attempted to research further and somehow decided what I really needed was rebase:

git rebase dreamhost/master matt_working

Open in new window


Sadly, for whatever reason this resulted i a huge confusing mess for which I was very ill-prepared. #-way merging, whitespace errors, what have you. Now I was in git limbo, and a git status revealed I was no longer on any branch, and my local site was gone. So I checked out the branch I was trying to push as a subtree, and everything was back.

I should have stopped here and called for help, but I continued to plow forward, attempting to simply pull the dreamhost/master branch into my working one. I was already up-to-date.

So I aborted the rebase, and that reset my head to the merge

git rebase --abort

Open in new window


So now I just wanted to forget all this and go back to where I was when I started. I tried to do a hard reset to that commit, but instead it reset to the merge, and I can't seem to get rid of the thing.

All this is to say I have no clue what I'm doing, what I've done, and how I can undo it and hopefully walk away the wiser and able to continue on with this website. Key to the latter is being able to reliably push the dist folder to the server, but that error keeps getting thrown, and right now I have a branch that has a subtree merged with it, which seems like it can't be a good thing. Clearly I need some hand holding, but I've been unable to find anyone who can explain this stuff to me and help lift me out of this mess.

I can provide much more detail if I know what blanks need to be filled in. Not unlike a chimp, I can be taught, but this chimp is pretty lost right now.

EDIT: I should probably sum this up with my actual questions:

How can I return to a the state I was in at my last commit, before I tried all this merging and rebasing?

How can I sync up my dist folder with the dreamhost repo so that I can deploy changes to the host?
KlaytnAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

evilrixSenior Software Engineer (Avast)Commented:
Have you considered that maybe git isn't the right tool for this? Git is a version control system and, yes, it can be used to push data around but it's hardly its razon de entre. Maybe you should take a look at using something like rsync or even plain old FTP for publishing the site.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
evilrixSenior Software Engineer (Avast)Commented:
You can use git reflog to figure out the point on your local repo when you started messing things up and do a hard reset back to the reference. Unfortunately, reflog isn't the easiest of things to pick through so you'll have to be a bit patient whilst trying to figure out what you started from.

Do you understand the difference between merging and rebasing? When you merge you take all the stuff from the source branch and shove it on top of the destination branch. when you rebase you take all the stuff from the source branch and shove it underneath all your chances since the point where the two branches diverged. It's like you are doing a reverse merge. You normally rebase your development branch onto the release branch so that your changes are the very last things in the commit line and then you merge your branch into the release branch. When in doubt, merge - because it doesn't screw up your history; whereas, rebase does.

https://www.atlassian.com/git/tutorials/merging-vs-rebasing/

If you've not done so, I recommend you take time to read this free (and very very very useful) git book.
https://progit.org/
http://git-scm.com/book/en/v2

Hope this (sort of) helps :)
KlaytnAuthor Commented:
The KISS principle applies. FTP seems to be the way to go. To this day I'm not sure why my dev wanted to set it up to deploy via git, but some mysteries will never be solved.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Git

From novice to tech pro — start learning today.