JGit:推送到特定分支
我在github上有两个分支:master和development。 我想将新创建的文件推送到开发分支JGit:推送到特定分支,git,branch,push,jgit,Git,Branch,Push,Jgit,我在github上有两个分支:master和development。 我想将新创建的文件推送到开发分支 String user = "user"; String password = "password"; String localPath = "local"; String remotePath = "https://github.com/some/git.git"; Git.cloneRepository().setBranch("refs/heads
String user = "user";
String password = "password";
String localPath = "local";
String remotePath = "https://github.com/some/git.git";
Git.cloneRepository().setBranch("refs/heads/development").setURI(remotePath).setDirectory(new File(localPath)).call();
Git localGit = Git.open(new File(localPath));
localGit.checkout().setName("origin/development").setUpstreamMode(SetupUpstreamMode.TRACK).call();
new File("local/test").createNewFile();
localGit.add().addFilepattern(".").call();
localGit.commit().setMessage("message").call();
localGit.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)).call();
我得到的是一个
TransportException: Nothing to push.
有什么问题吗
更新:
我可以通过删除checkout命令使其工作。因为克隆已经签出了指定的分支,我以前不清楚 通过签出
origin/development
(即“origin
”)您已经创建了一个与0本地分支关联的头(即,不是与refs/head/development
,而是与refs/remotes/origin/development
)
这就是为什么git push
返回“nothing to push”,因为没有本地分支接收到任何新的提交to push
您需要确保:
- 签出本地“
”分支(您使用development
,尽管我更喜欢使用.setBranch(“development”)
,以确保引用本地分支).setBranch(“refs/head/development”)
- 使“
”成为“起源/发展
”的上游分支。发展
或者至少,像这样,使用正确的refspecdevelopment:development