git clone gets gh-pages, I want it to clone master (from Github)
-
28-05-2021 - |
Question
One day I couldn't remember where my main working directory for my folder was, so I just decided to clone the project from the "git@github.com:" address that's on the github web page.
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.
Solution
Q1: git clone http://remote.url/repo.git -b master
Q2: 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
e.g.
$ git help clone
OTHER TIPS
Q1: Changing Default Branch to master
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 master
.
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
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 git@github.com:username/repo.git :gh-pages
or:
git push --delete git@github.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 gh-pages
branch:
git checkout master
git branch -D gh-pages
Q3:
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>