Can I redirect one branch of a GitHub repository? - github

I know that GitHub has automatic redirects if you move/rename an entire repo. But I have the following scenario:
Project whizbang has several branches.
One of the branches needs to be moved into its own repository, so that whizbang/8.x branch becomes a new repository named whizbang8.
Old links pointing to project whizbang/8.x branch need to be
redirected to the new repository.
Is this possible?

Old links pointing to project whizbang/8.x branch need to be redirected to the new repository.
Not that I know of: a GitHub URL for a branch later exported in its own repo would still point to the old repo (branch), and not to the new repo.

Related

Is it possible to only have one gh-pages repo?

Last year I have been working on a project, that required gh-pages. Everything was totally fine and hosted on Github Pages. Today I started to work on another project, that will also require gh-pages. However when I started pushing local repo to github, I realized something. Somehow this newly created react app already had a remote origin with a link to that first last-year repo. How is it possible? Will my first repo stop working if I use gh-pages with this new project?
gh-pages pages is (or, rather, should be!) a branch not a repo. Your new new project should be in a new repo. Two repos can, of course, both have branches with the same name.
It sounds like you have set up the repos or the remotes for the repos incorrectly. Can you please edit your question to add the URLs of the two repos and the results of running git remote -v in the local checkouts of the two repos.

How to work on a project fork when having the original in Eclipse?

I'm trying to create a pull request on GitHub for project "original/QWERTY" so I forked the repo to "Mark/QWERTY". In Eclipse, I already have a repository set up for "original/QWERTY" and that project is in my workspace, named QWERTY.
Now if I create a new repository pointing at "Mark/QWERTY", I'll have two projects with the same name and both Eclipse and me won't like it.
I thought that it should be possible to have a branch or another remote under a repository and switch between them instead of having two copies (I mean just store the diffs). The problem is that they are different projects on GitHub so I'm not sure how to do it.
What is the correct way to set up two GitHub projects to create a pull request from my fork to the original one in Eclipse with EGit?
The usual workflow for forked repositories is to have a single local repository with a single work directory that is configured to fetch and push from/to multiple remote repositories.
With this setup, you can switch between branches that originate from different remote repositories.
The Fork a repo documentation of GitHub explains this setup when using CLI Git. Most of it should also apply to repositories hosted elsewhere.
Using the EGit documentation, it should be possible to translate these instructions into the corresponding actions in EGit.
How to manage multiple remotes with EGit is documented here: https://wiki.eclipse.org/EGit/User_Guide#Remote_Repositories
Using the information from Rudiger's comment and answer and my trial and error with branches I made my own steps. This picture also helps with terminology.
First, do these 2 things in any order:
fork the original project in the github website so now you have the original and the fork. They have the same code and branches.
create a local repository pointing to the original repo on github. Let's say you decided to select only the master branch.
Remotes: you get a new remote I'll call origin (default). configure its fetch if it's not done for you, the default specification is +refs/heads/*:refs/remotes/origin/*. This ref spec maps all the repo branches to Remote Tracking branches with the same name. If you want to only fetch the master branch then use +refs/heads/master:refs/remotes/origin/master.
Branches: you get a "Remote Tracking" branch called origin/master and a local branch called master with configuration of "Remote: origin" and "Upstream Branch: refs/heads/master". You will be working under the local master as it's the only branch right now.
Now you want to be able to push to your fork so you can create PR. You can and already did pull from the original to keep getting updates from other people's work.
Right click on "Remotes" and create a new remote, I'll call it fork (call it whatever you need). Configure its push.
the URI points to your fork the same way the origin Remote URI points to the original.
The ref mapping maps the branches. Go to "Advanced" and click "Add All Branch Specs" if it isn't done for you. You should get the spec refs/heads/*:refs/heads/*. It's easy to work with this spec but you can change it to whatever you need.
Create a local branch (right click -> switch to -> new branch) whose source is the local branch named master and the branch name is whatever suits what it does. it can be the master branch or a new branch that let's say fixes a bug, so bug 123. You do not have a Remote Tracking branch because those are used for pulls. If you also pull from fork then you will need to configure that in the Remote fork and get a remote branch.
Now you are working on a local branch bug 123 (you can see a checkmark next to it). Fix the bug in your code and in the Git Staging view you should see the files changed and the title is <Repository name> [bug 123]. Make sure you are going to commit/push to the correct branch! Stage whatever you need and commit (adds the changes to the local branch bug123) and push (creates a branch on the github repo called bug 123 if you stayed with the default spec).
Now go to the GitHub repo page of either the original or the fork and the UI will tell you that you can create a PR. From there GitHub will guide you.
Once the PR is merged into the master branch of the original on GitHubm, you will want to fetch from the master.
Right click on the Remote origin or its fetch "subdir" and choose fetch. The will fetch any changes in all the remote branches because the fetch spec we used maps all the branches (we used the * character).
That's it. Continue to switch to a local branch which maps to your fork based on the updated master, fix bug, commit and push, create PR, wait for merge into the original, fetch and pull from the original.

github site from gh-pages branch

I have GitHub site like example.github.io and want to load this site from the gh-pages branch!
how can I do?
now I can't change branch because my repository name is example.github.io
When you create yourusername.github.io you have to commit directly to master. It's meant as a website (unlike a repo that has a website that hosts to yourusername.github.io/reponame/*.
Since you already have a branch with the website, just merge it into the master branch. This can be done from the command line, the Github website or Github Desktop.
The logic
Example: You have a repo (username.github.io). You also have two repos set up with Github pages: repo-1 and repo-2.
username.github.io is the root. You're free to do pretty much anything you want with it. Creating directories will be relative to the root of the domain. When you connect to the domain, it finds the files from the master branch. If you go into the repo settings for username.github.io, you'll see this:
You're locked to the master branch. You can still use other branches for adding features, but what the actual website consists of is what's on the master branch.
The difference between the username.github.io repo and repo-1 or repo-2 is that username.github.io allows editing access to the directory root (e.g. http(s)://username.github.io/index.html) where as repo-1 and its connected pages would be at http(s)://username.github.io/reponame/index. Since the website is most likely wanted to stay out of the source itself, you can use an alternate branch to host it.
If you go into settings for repo-1 or repo-2, you'll see this:
Here you can pick. If you have multiple branches, you can select a different one to host the pages. You can also select the option to use the /docs folder for the website.
TL:DR; When using username.github.io, the master branch is the one that actually hosts the website. Think of it as the production branch. The others can't be accessed from the website
From the OP's comment:
So I can't use the gh-pages branch for Github site! yes?
Update Sept. 2020: yes, you now can.
You can use any branch you want.
"Build and deploy GitHub Pages from any branch"
Repositories that use GitHub Pages can now build and deploy from any branch.
Publishing to the special gh-pages branch will still work the same as it always has, but you can now choose a different branch in your repository as the publishing source.
This functionality also removes the hardcoded dependency on user and organization pages having a master branch.

Can GitHub pages automatically build a Jekyll site on commit to gh-pages?

I am learning how to use jekyll and would love it if someone could explain how to set it up so that whenever I commit the jekyll files to the gh-pages branch, the site would be automatically generated.
Thank you
Reading the documentation pointed by #thirtythreeforty's comment
For User Pages, use the master branch in your username.github.io repository. For Project Pages, use the gh-pages branch in your project's repository.
if your repository is at github.com/userName/userName.github.io it's your user repo -> publish to master
any other repository like github.com/userName/projectName is a project repository -> publish to gh-pages
So, be sure to commit in the right branch.
If the problem is elsewhere you can give your repository url for further investigation.

New to github. Fork or branch?

I'm new to github. I just downloaded the Windows GUI github version. I want to contribute to someone's project. Should I fork the original repo to my repo and start from there or should I branch off from the original repo? How do I merge it back to the original repo later? How to do this on the GUI or do I need to use Git shell?
Unless the original author lets you push to his repo, you won't be allowed to do it. The usual process to contribute to a project you don't own is to:
create a fork of the repo
clone the fork you've just created to work on it locally
create a branch to add your contribution
add commits to this branch
push it to your forked repo on github
send a pull request to the original repo on github so that the author can fetch the branch from your repo, test it, and integrate it if he likes it.
This is explained when you click on the giant 3 - Fork a repository link on Github's home page