Git clone gets gh pages, I want it to clone master (from Github)
One day, I couldn't remember where my main working directory for my folder was, so I decided to clone the project from "git @ github.com:" located on the github web page.
I didn't know what I was doing that day and after that I created a bunch of things in the directory. Then I did git add, git clone and git push, (I forgot how). But now I have this branch called "gh-pages" on github site. I really wish I had this branch, but I know.
Today I found my source directory and today I created something in it and did some "add" and "push". It went to the "branch" of the master (which I expected because I kind of gave up hope on another strange branch). But now my problem is:
When my users (I tried this on a different machine myself) make a git clone using the URL that github gives me on my project's homepage), they end up getting the code from the gh-pages branch for some strange reason.
Q1: How do I get them to do a git clone so they can get stuff I was working on today (which is in the master branch).
Q2: how to remove the gh-pages branch from github site? I decided to give it up. If you have a better suggestion, I am also susceptible to that. Q3: Bonus points if you can tell me what I should have done before once I realized that I have two locations on my computer that has code for two separate branches in my project on github.
source to share
Q1: change the default branch to master
Based on your description, it looks like your default branch is set to gh-pages
instead of master
. To fix the error, log into GitHub, click on your repository, click on the Admin button, and change the Default section to master
.
What this means is change the symbolic link HEAD
in your GitHub repository to point refs/heads/master
instead of refs/heads/gh-pages
. When cloning a repository, Git looks at the link to the remote repository HEAD
and uses that as the default branch to checkout. See my answer to another question for details . Usually HEAD
points to refs/heads/master
new bare repositories, but Git (and GitHub) allows you to change it.
Q2: delete a branch gh-pages
A fork gh-pages
is a special branch that GitHub uses to upload content to project pages .
To remove yours gh-pages
from the 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 commands above will gh-pages
only remove the branch from the GitHub repository - it will not remove the branch gh-pages
from your local repository. To delete a local branch gh-pages
:
git checkout master
git branch -D gh-pages
source to share
Q3:
If I understand correctly, you have the same repo cloned twice into two separate folders and each clone has a different branch with some useful code.
I think you need to select the clone you want to keep, then create a new branch with the same name of another clone branch. The following command will create a new branch and check it out automatically.
git checkout -b <other-branch-name>
Assuming another branch has already been pushed to Github, you simply pull it to the branch you want to keep.
git pull --rebase origin <other-branch-name>
If you haven't pushed another branch yet, publish it to the server and upload it.
git push origin <other-branch-name>
Alternatively, you can do straight from source to destination branch, but I don't know how well that works. Disclaimer , never tried it myself in production but I know this is correct and it should work.
git push origin <other-branch-name>:<current-branch>
source to share