Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting started with GitHub and Eclipse (spring source toolsuite 2.7.1)

I am new with both Git and GitHub so please bear with me. I have an empty repository on GitHub with an automatically created branch (gh-pages), which, I understand, is supposed to be used with GitHub's pages functionality.

Now what I would like to do is to create and eclipse project from which I could commit/push to this repository.

What is confusing me that I can't see any option to create a remote branch on github. I suppose pushing my source to gh-pages won't be a good idea. BTW, I also don't understand why the GitHub pages is feature is implemented as a branch? Aren't branches supposed to be merged with each other at some point. Clearly it wouldn't make any sense to merge github pages into my project. Wouldn't it be better to have a folder within my project for this purpose.

I googled and found this link but being a git noob I am not sure if that's what I want to do. I would like to use Eclipse as my primary interface to git and github only falling back to command line or other interfaces when there is no other option.


OK I think I have figured it out. Basically, what you need is to define a remote ref that need not exist before hand.

  1. Create a project
  2. Team->Share it to a local repository
  3. In the repository view (Window->Show View-> Git -> Repositories) select the local repository and right click on remotes
  4. Select new remote (configure push). Type origin in the remote name. Press OK
  5. Change URL. Copy/paste the ssh uri from github. Select ssh protocol (make sure you have ssh key defined in eclipse SSH preferences, and uploaded to github)
  6. Now the last part is to add Ref mapping. Click on Add.. in ref mapping section of screen. And enter refs/heads/master in both local and remote branches.

Or may be the refs/heads/master on both side isn't a good idea :) I see, cloning a github repo that doesn't have gh-pages branch is simpler as it automatically creates this remote fetch spec

Remote Fetch Specification +refs/heads/*:refs/remotes/origin/*

Maybe this is what I need to enter in the step 6 above


Ok as it turned out the original idea of "refs/heads/master in both local and remote branch" was correct. Pushing with this configuration is showing my changes in git hub correctly. The second option on the other hand is failing silently.

like image 246
Shamaila Tahir Avatar asked Jul 16 '11 21:07

Shamaila Tahir


1 Answers

Branches typically are used in the way you described, but nothing says they must be used that way. This is just the way github chose to let you manage your page content, and it works quite well. It's kind of similar to hosting multiple repos on one SVN server.

As for creating new repos, if you create a repo in github and then clone it, you'll have an empty repo locally that already points to github with a remote named "origin". This is a convenient way to start out, since you don't have to mess with adding a remote yourself. At this point, your repo has no commits and no branches in it. When you make the first commit, it will automatically establish a branch named "master". I don't know how eclipse is set up by default, but from the command line with default settings, you have to explicitly push new branches to a remote or else they won't get pushed at all. I.e. making the first commit and doing git push will just fail with a message like "No refs in common and none specified; doing nothing". Instead, you have to git push origin master to tell it to establish the "master" branch in remote "origin" (aka github). Thereafter, just a git push will work fine.

Hope that clears up some of your confusion.

like image 137
Ryan Stewart Avatar answered Sep 29 '22 01:09

Ryan Stewart