1

I have some repository, like https://nickname@bitbucket.org/nickname/repo-name.git. I need to push some data to this repo, using Java.

So, basically I want to do these steps:

  1. Create temporary directory (tmp_path == /temp/tmp/dir)
  2. cd tmp_path
  3. git init
  4. git remote add origin https://nickname@bitbucket.org/nickname/repo-name.git
  5. create temp file with needed data (filanme == tmpfile.txt)
  6. git add filename
  7. git commit --message="adding tmp file"
  8. git push origin tmp-branch

But there is one problem. I cannot make "cd" from Java. So I need another solution.

Is there any way to push some data to repository without local git folder?

Max
  • 1,803
  • 3
  • 25
  • 39
  • 1
    Do you plan to start new processes to execute these commands? If so, yes, there is a way to start the process from a specific directory: https://docs.oracle.com/javase/8/docs/api/java/lang/ProcessBuilder.html#directory-java.io.File-. But there are Java APIs to use git from Java, without starting processes. It's unclear what you actuallly want to do, since you didn't post any code. – JB Nizet Sep 29 '18 at 12:07
  • @JBNizet my final target is to push List of userData to some branch of specific git repo. Thank you for link, I will see it. – Max Sep 29 '18 at 12:16

1 Answers1

3

I'm not familiar with Java, so I can just give commands without cd.

git init /temp/tmp/dir
# create tmpfile.txt in /temp/tmp/dir
git --git-dir=/temp/tmp/dir/.git --work-tree=/temp/tmp/dir add tmpfile.txt
git --git-dir=/temp/tmp/dir/.git commit --message "adding tmp file"
# your question says without adding remote, so we skip "git remote add"
git --git-dir=/temp/tmp/dir/.git push https://nickname@bitbucket.org/nickname/repo-name.git HEAD:refs/heads/tmp-branch
ElpieKay
  • 27,194
  • 6
  • 32
  • 53