-1

I'm working on a basic Angular 5 project that I keep updated in the master branch on my github account. I recently added a live version of my project to github pages using the following tutorial: here where the following commands were run:

ng build
git add dist
git commit -m "checking in dist folder"
git subtree push --prefix=dist origin gh-pages 

The above lines only pushed the contents of the /dist folder to the remote repo origin/gh-pages and this is where my live site (front-end) was loading from.

So after making changes and committing to my master branch in my local repo, I tried to sync the the origin/gh-pages branch as well (using a guide). But I receive the following errors and I have a feeling I'm doing (or did) something incorrectly. I'm quite new to Git and I don't understand the issue.

lycan@lycan-dmini110 /media/lycan/Store4/WebDevelopment/Angular/SampleProjects/address-book-angular $ git branch
* master
lycan@lycan-dmini110 /media/lycan/Store4/WebDevelopment/Angular/SampleProjects/address-book-angular $ git checkout gh-pages
Branch 'gh-pages' set up to track remote branch 'gh-pages' from 'origin'.
Switched to a new branch 'gh-pages'
lycan@lycan-dmini110 /media/lycan/Store4/WebDevelopment/Angular/SampleProjects/address-book-angular $ git rebase master
First, rewinding head to replay your work on top of it...
Applying: checking in dist folder
lycan@lycan-dmini110 /media/lycan/Store4/WebDevelopment/Angular/SampleProjects/address-book-angular $ git status
On branch gh-pages
Your branch and 'origin/gh-pages' have diverged,
and have 17 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

nothing to commit, working tree clean
lycan@lycan-dmini110 /media/lycan/Store4/WebDevelopment/Angular/SampleProjects/address-book-angular $ git push
Username for 'https://github.com': ************
Password for 'https://***********@github.com':
To https://github.com/<github username>/address-book-angular.git
 ! [rejected]        gh-pages -> gh-pages (non-fast-forward)
error: failed to push some refs to 'https://github.com/<github username>/address-book-angular.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
lycan@lycan-dmini110 /media/lycan/Store4/WebDevelopment/Angular/SampleProjects/address-book-angular $ git pull
fatal: refusing to merge unrelated histories
lycan@lycan-dmini110 /media/lycan/Store4/WebDevelopment/Angular/SampleProjects/address-book-angular $ git rebase master
Current branch gh-pages is up to date.
lycan@lycan-dmini110 /media/lycan/Store4/WebDevelopment/Angular/SampleProjects/address-book-angular $ git push origin gh-pages
Username for 'https://github.com': <github username>
Password for 'https://<github username>@github.com':
To https://github.com/<github username>/address-book-angular.git
 ! [rejected]        gh-pages -> gh-pages (non-fast-forward)
error: failed to push some refs to 'https://github.com/<github username>/address-book-angular.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
lycan1385
  • 127
  • 1
  • 10
  • Possible duplicate of [Cannot push to GitHub - keeps saying need merge](https://stackoverflow.com/questions/10298291/cannot-push-to-github-keeps-saying-need-merge) – phd Apr 07 '18 at 16:04

1 Answers1

0

I solved the issue, by deleting my remote repo origin/gh-pages (origin/master was unaffected). and then ran the following commands I used previously (that I saw in the tutorial):

ng build
git add dist
git commit -m "checking in dist folder"
git subtree push --prefix=dist origin gh-pages

This allowed the latest changes from the local master branch to be pushed to the origin/gh-pages remote branch and my site is live again on github pages.

lycan1385
  • 127
  • 1
  • 10