git clone gets gh-pages, I want it to clone master (from Github)
I didn’t know what I was doing that day, and I created a bunch of stuff after that in the directory. Then I did git add, git clone, and git push, (I forget how). But now I have this branch called ‘gh-pages’ on the github site. I really wish I didn’t have that branch, but I do.
Today I found my original directory and I created some stuff in it today, and did some ‘add’ and some ‘push’. It went to the master ‘branch’ (which I expected, because I kinda gave up hope on the other weird branch). But my problem is now this:
When my users (I tried this on another machine myself) do a git clone by using the address that github gives me on the main page of my project), they for some weird reason end up with the code from the ‘gh-pages’ branch.
Q1: How do I have them do a git clone so that they can get the stuff that I worked on today (which is in the master branch).
Q2: how do I remove the ‘gh-pages’ branch from the github site? I decided to abandon it. If you have a better suggestion, I’m receptive to that too.
Q3: Bonus points if you can tell me what I should have done earlier on, once I realized I have two places on my pc that has code for two separate branches in my project on github.
3 Solutions collect form web for “git clone gets gh-pages, I want it to clone master (from Github)”
git clone http://remote.url/repo.git -b master
git push origin :gh-pages, assuming
origin is the remote you want to work on.
BTW, git comes with pretty good documentation. It can be accessed with
$ git help command
$ git help clone
Q1: Changing Default Branch to
Based on your description, it sounds like you have your default branch set to
gh-pages instead of
master. To fix, log in to GitHub, click on your repository, click on the Admin button, and change Default Branch to
What this does is alter the
HEAD symbolic reference in your GitHub repository to point to
refs/heads/master instead of
refs/heads/gh-pages. When cloning a repository, Git looks at the remote repository’s
HEAD reference and uses that as the default branch to check out. See my answer to a different question for more details. Normally
HEAD points to
refs/heads/master on new bare repositories, but Git (and GitHub) allows you to change it.
Q2: Delete the
gh-pages branch is a special branch GitHub uses for uploading content to project pages.
To delete your
gh-pages from your GitHub repository:
git push firstname.lastname@example.org:username/repo.git :gh-pages
git push --delete email@example.com:username/repo.git gh-pages
Note that the above commands will only delete the
gh-pages branch from your GitHub repository — it won’t delete the
gh-pages branch from your local repository. To delete the local
git checkout master git branch -D gh-pages
If I understood correctly, you have the same repo cloned twice in two separate folders, and each clone has a different branch with some usable code.
I think you have to choose the clone you want to keep then create a new branch with the same name of the other’s clone branch. The following command will create a new branch and automatically checkout to it.
git checkout -b <other-branch-name>
Assuming that the other branch is already pushed on Github, you just pull it to the branch you want to keep.
git pull --rebase origin <other-branch-name>
If you haven’t already pushed the other branch, publish it to the server and upload it.
git push origin <other-branch-name>
Alternatively, you can do a straight from the source to the destination branch, but I don’t know how well this works. Disclaimer, never tried it myself on production mode, but I know it’s correct and it should work.
git push origin <other-branch-name>:<current-branch>