2

Here’s an example of how to do this on Bitbucket: Manually create a Git fork. I may use their command line API to fork a project on Bitbucket, but I need to at least read the root project permissions.

Here's the syntax:

curl -v --user {username}:"{password}" \ 
https://bitbucket.org/api/1.0/repositories/{accountname}/{repo_slug}/fork \ 
--data "name=mynewrepo"

To fork Project A from an account B to my account C with the name Project D, I will use the following command:

  1. curl -v --user XYZ:"XYZPASSWORDXYZ" \ https://bitbucket.org/api/1.0/repositories/ABC/ProjectABC/fork \ --data "name=ProjectXYZ"

  2. Now, I will clone this project to my local machine, git clone [project]

  3. I will go to my project directory and add remote upstream which will point to the source repository: git remote add upstream [git]

  4. Now, at anytime to pull the changes from source repository (say from master branch), I will use: git pull upstream master and to push my local commits to my target repository on server, I will use: git push origin master

And when your changes on target repository are ready to be merged with the source repository, create a Pull Request either from Bitbucket website or using Bitbucket API: Pull Request

However, if you will calculate your time doing this stuff, it can take 30 seconds to 2 minute if you have slow system. My point is, is there a way to send Pull Request using only 1 command that will do it all without all this stuff?

Edison Pebojot
  • 308
  • 3
  • 15

2 Answers2

2

I solved it, by following the documentation given from GitHub CLI Manual. It is so easy to create a Pull Request by using the command line: gh pr create

Edison Pebojot
  • 308
  • 3
  • 15
1

If you are having issues with your download speed, you may try to only download a partial part of the repository's history using shallow clones :

# on cloning :
git clone <url> --depth 1

# on fetching :
git fetch --depth 1 origin <branch>

Note that shallow clones have limitations of their own, like not being able to inspect the complete history (obviously ...) or failing to merge or rebase in some situations, if you don't have enough history locally to find the common ancestor of two branches.

You can however deepen a shallow clone on demand, by fetching a deeper history of the branches you need :

git fetch --depth 20 origin master
git fetch --depth 100 origin develop

If the slowness stems from the api calls, you would have to look closer at the documentation to see if you can fulfill your needs using cheaper calls.


If you are having issues when running local commands or when pushing, I don't see how to avoid those operations.

You may want to look into how you could perform your work on a remote machine, which would have decent cpu-power and/or upload speed.

LeGEC
  • 46,477
  • 5
  • 57
  • 104