2

I've got two branches on a repo in GitHub; one is the default branch master, and the other is called gh-pages. I set the default branch to be gh-pages on GitHub.

I use VS Code Editor to code my project (coder-in-pink), so I created a new branch named gh-pages in VS Code, and I committed my saved work in the source control.

I'm not allowed to embed pictures in my posts yet, so here's the little picture of the gh-pages branch I set in VS Code. (It might not be very helpful, though.)

But today I found out that it had been committed to the master branch. How do I move/transfer it to the gh-pages branch?

Thanks!

P.S. I'm planning to make the website with HTTPS and a custom domain afterwards, which is why I want to use the gh-pages branch.

Here's the link to my repo on GitHub => Coder In Pink.

  • Possible duplicate of [Move the most recent commit(s) to a new branch with Git](https://stackoverflow.com/questions/1628563/move-the-most-recent-commits-to-a-new-branch-with-git) – Robin Green Oct 19 '18 at 08:47
  • @RobinGreen, I think the answers tymtam and sublimegeek gave are a bit more helpful for me. –  Oct 21 '18 at 10:11

2 Answers2

2

Here's what I would do

  1. Merge master to gh-pages - this would bring the commit to gh-pages.

  2. Revert the commit in master, if needed, by git revert commit-id.


Update

I found this by coincidence.

The GitHub Blog's How to undo (almost) anything with Git has a section that matches your scenario.

Once more, with branching

Scenario: You made some commits, then realized you were checked out on master. You wish you could make those commits on a feature branch instead.

(...)

Community
  • 1
  • 1
tymtam
  • 31,798
  • 8
  • 86
  • 126
  • Okay, let me look into that first. –  Sep 03 '18 at 01:42
  • I've never done a merge before, so I'm looking it up on the web. –  Sep 03 '18 at 01:44
  • Can you tell me the steps to merge the branches? I'm a bit lost. –  Sep 03 '18 at 01:59
  • I think it's best if you refer to a tutorial. There is just not enough space here to explain it :) Here's an official one. https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging Good luck! – tymtam Sep 03 '18 at 02:06
  • Here's another one, also with pictures: https://www.atlassian.com/git/tutorials/using-branches/git-merge – tymtam Sep 03 '18 at 02:06
  • Thanks, @tymtam! Your tips have been really helpful. –  Sep 03 '18 at 02:10
1

git checkout gh-pages This makes sure you're on the gh-pages branch

git merge master This merges master into gh-pages

Finally git push origin gh-pages This will push your changes back to GitHub. Origin isn't needed, but this is the long-form way of doing it.

The short way is just git push while being checked out on gh-pages

sublimegeek
  • 110
  • 1
  • 8