1

Very new to git, so please bear with me. Using Bitbucket/Sourcetree if that matters.

We have some code not currently in source control anywhere.
For lack of a better term, let's think of them as Java projects.
Each project is in its own folder in a directory.
We have dozens of projects.

Is there an easy way to create a new repository for each project/folder and push it up to Bitbucket without doing it one by one?

I feel like I shouldn't make the root folder a repository since multiple projects would be checked out simultaneously and it would be confusing from a commit/push/deploy to the master branch perspective.

Again, I'm new to git, so maybe I'm not thinking of this correctly.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
mang
  • 163
  • 1
  • 1
  • 14
  • Is it so bad doing it manually? You only need to do it once... – evolutionxbox Jun 23 '21 at 22:51
  • 1
    I agree with Mason! Automate it with a (simple) script using some git terminal commands. I have done it onec to create pull request and stuff. Have you seen this? I guess it could help: https://www.freecodecamp.org/news/automate-project-github-setup-mac/ – Christian Jun 23 '21 at 23:08
  • I'm guessing this is done with the git command line? I've never programmed or run anything with linux but I can struggle through it with the examples you guys posted. Thanks for the help! I'll check back if I get hung up. – mang Jun 24 '21 at 03:17

1 Answers1

1

That should be managed by a script, which could:

  • do a git init in each Java project folder
  • add, commit
  • git remote add origin https://bitbucket.org/me/<newProjectW
  • and also: create the new remote repository directly from the same script.

See "Create repo on Bitbucket programmatically"

curl -X POST --user 'user:app_pass'  \ 
    -H "Content-type: application/json" \
    -d '{"project":{"key":"PROJ"}}'     \
   "https://api.bitbucket.org/2.0/repositories/USER/REPO" 
  • finally: git push -u origin main

That way, in one script, you do everything.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks. Where do you run this? git command line or windows command line? I've never used curl. – mang Jun 24 '21 at 03:52
  • @mang All those steps, including curl, can be executed from a bash script (which runs even on Windows, considering bash is included in Git for Windows). – VonC Jun 24 '21 at 06:32