user2242849
user2242849

Reputation: 139

jgit - clone a branch of a repo without a checkout

The CloneRepository command seems to ignore the setBranch parameter if you aren't doing a checkout. Is there a way to specify the branch ( instead of the master )? I don't want to checkout the entire branch but I want to add a file to that branch ( add, commit, and push )

Upvotes: 2

Views: 2993

Answers (1)

centic
centic

Reputation: 15872

This works for me when I use the existing snippet for cloning from the jgit-cookbook and only add the following at line 33:

            .setBranch("email")

After the snippet is executed, the local clone in the temporary directory has the given branch checked out.

Another option might be to use org.eclipse.jgit.storage.dfs.InMemoryRepository to clone a Git repo in-memory and work from there.

Upvotes: 2

Related Questions