diff --git a/AUTHORS b/AUTHORS index a449ad5..64a1091 100644 --- a/AUTHORS +++ b/AUTHORS @@ -237,3 +237,4 @@ Patches and Suggestions - Étienne BERSAC - ☃ pitr - 单元源 +- Don 'duckunix' Harper diff --git a/bin/git-fork b/bin/git-fork index 7c651be..0fd9994 100755 --- a/bin/git-fork +++ b/bin/git-fork @@ -14,10 +14,12 @@ test -z "$url" && abort "github repo needs to be specified as an argument" echo "Enter your github username" read user [ -n "$user" ] || abort "git username required" -echo "Enter github password for user \"$user\"" -read -s passwd -echo "Enter github two-factor authentication code (leave blank if not set up)" -read MFA_CODE +# personal access token +# config name is github-personal-access-token '_' is not allowed in git config + +github_personal_access_token=$(git config git-extras.github-personal-access-token) + +test -z "$github_personal_access_token" && abort "git config git-extras.github-personal-access-token required" # extract owner + project from repo url project=${url##*/} @@ -35,7 +37,7 @@ fi # create fork curl -qsf \ -X POST \ - -u "$user:$passwd" \ + -u "$user:$github_personal_access_token" \ -H "X-GitHub-OTP: $MFA_CODE" \ "https://api.github.com/repos/$owner/$project/forks" diff --git a/man/git-fork.1 b/man/git-fork.1 index 777a38c..e259745 100644 --- a/man/git-fork.1 +++ b/man/git-fork.1 @@ -40,6 +40,20 @@ adds the forked repo as a remote called \fBorigin\fR .P Remotes will use ssh if you have it configured with GitHub, if not, https will be used\. . +Create a fork a project on GitHub via command line\. +. +.P +A personal access token is required for making the API call to create a new fork in GitHub\. API Documentation here \fIhttps://docs\.github\.com/en/rest/reference/repos#forks\fR +. +.P +Make sure the personal access token has the right \fBOAuth\fR scopes for the repo(s) +. +.P +Use \fBgit config \-\-global \-\-add git\-extras\.github\-personal\-access\-token \fR +. +.P +If using multiple accounts, override the global value in the specific repo using \fBgit config git\-extras\.github\-personal\-access\-token \fR +. .SH "EXAMPLE" Fork expect\.js: . diff --git a/man/git-fork.html b/man/git-fork.html index 9c68ce3..3ad0fbf 100644 --- a/man/git-fork.html +++ b/man/git-fork.html @@ -99,6 +99,16 @@

Remotes will use ssh if you have it configured with GitHub, if not, https will be used.

+

Create a fork of a project on GitHub via command line.

+ +

A personal access token is required for making the API call to create a new fork in GitHub. API Documentation here

+ +

Make sure the personal access token has the right OAuth scopes for the repo(s)

+ +

Use git config --global --add git-extras.github-personal-access-token <your-personal-access-token>

+ +

If using multiple accounts, override the global value in the specific repo using git config git-extras.github-personal-access-token <other-acc-personal-access-token>

+

EXAMPLE

Fork expect.js:

diff --git a/man/git-fork.md b/man/git-fork.md index 890c5d9..701ac87 100644 --- a/man/git-fork.md +++ b/man/git-fork.md @@ -21,6 +21,16 @@ git-fork(1) -- Fork a repo on github Remotes will use ssh if you have it configured with GitHub, if not, https will be used. + Create a fork of a project on GitHub via command line. + + A personal access token is required for making the API call to create a fork in GitHub. [API Documentation here](https://docs.github.com/en/rest/reference/repos#forks) + + Make sure the personal access token has the right `OAuth` scopes for the repo(s) + + Use `git config --global --add git-extras.github-personal-access-token ` + + If using multiple accounts, override the global value in the specific repo using `git config git-extras.github-personal-access-token ` + ## EXAMPLE Fork expect.js: