Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit » How to clone or checkout a specific branch ? (Check out a branch)
How to clone or checkout a specific branch ? [message #934097] Fri, 05 October 2012 12:53 Go to previous message
kaleeswaran S is currently offline kaleeswaran S
Messages: 3
Registered: September 2012
Junior Member
In my java application i am using Jgit to clone the github project. It is working fine. My scenario is i am having git repo with branches like (master, kalees).

I want to checkout a specific brach kalees. How to checkout a branch using Jgit.

My code so far i am using is

Git repo = Git.cloneRepository().setURI(url).setDirectory(directory).call();
for (Ref b : repo.branchList().setListMode(ListMode.ALL).call()) {
S_LOGGER.debug("(standard): cloned branch " + b.getName());
}
repo.getRepository().close();

Which clones the github repository. and i tried to checkout a kalees branch like

repo1.checkout().setForce(true).setName("kalees").call();

It does not checkout the master branch only..

if i use jgit like repo1.checkout.setName("refs/remotes/origin/kalees").call();

it checkout the kalees branch. Is this the correct way to checkout a branch ???

If this is correct , i am using jgit pull command

Git git = Git.open(new File(dir)); //checkout is the folder with .git
git.branchCreate().setForce(true).setName("kalees").call();
CheckoutCommand checkout = git.checkout();
Ref call = checkout.setName("kalees").call();
git.pull().call();

which throws error like it
throws org.eclipse.jgit.api.errors.DetachedHeadException: HEAD is detached.
What could be the , whether this is a checkout issue or pull issue ?
 
Read Message
Read Message
Previous Topic:EGit does not honor ~/.hushlogin
Next Topic:rebase fails: "cannot delete file"
Goto Forum:
  


Current Time: Wed May 22 20:06:50 EDT 2013

Powered by FUDForum. Page generated in 0.07511 seconds