Skip to content

Commit b225ed4

Browse files
authored
Merge pull request #928 from duckunix/master
2 parents 206fe7c + 30383f9 commit b225ed4

File tree

5 files changed

+42
-5
lines changed

5 files changed

+42
-5
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,4 @@ Patches and Suggestions
237237
- Étienne BERSAC
238238
- ☃ pitr
239239
- 单元源
240+
- Don 'duckunix' Harper

bin/git-fork

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ test -z "$url" && abort "github repo needs to be specified as an argument"
1414
echo "Enter your github username"
1515
read user
1616
[ -n "$user" ] || abort "git username required"
17-
echo "Enter github password for user \"$user\""
18-
read -s passwd
19-
echo "Enter github two-factor authentication code (leave blank if not set up)"
20-
read MFA_CODE
17+
# personal access token
18+
# config name is github-personal-access-token '_' is not allowed in git config
19+
20+
github_personal_access_token=$(git config git-extras.github-personal-access-token)
21+
22+
test -z "$github_personal_access_token" && abort "git config git-extras.github-personal-access-token required"
2123

2224
# extract owner + project from repo url
2325
project=${url##*/}
@@ -35,7 +37,7 @@ fi
3537
# create fork
3638
curl -qsf \
3739
-X POST \
38-
-u "$user:$passwd" \
40+
-u "$user:$github_personal_access_token" \
3941
-H "X-GitHub-OTP: $MFA_CODE" \
4042
"https://api.github.com/repos/$owner/$project/forks"
4143

man/git-fork.1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ adds the forked repo as a remote called \fBorigin\fR
4040
.P
4141
Remotes will use ssh if you have it configured with GitHub, if not, https will be used\.
4242
.
43+
Create a fork a project on GitHub via command line\.
44+
.
45+
.P
46+
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
47+
.
48+
.P
49+
Make sure the personal access token has the right \fBOAuth\fR scopes for the repo(s)
50+
.
51+
.P
52+
Use \fBgit config \-\-global \-\-add git\-extras\.github\-personal\-access\-token <your\-personal\-access\-token>\fR
53+
.
54+
.P
55+
If using multiple accounts, override the global value in the specific repo using \fBgit config git\-extras\.github\-personal\-access\-token <other\-acc\-personal\-access\-token>\fR
56+
.
4357
.SH "EXAMPLE"
4458
Fork expect\.js:
4559
.

man/git-fork.html

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/git-fork.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ git-fork(1) -- Fork a repo on github
2121

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

24+
Create a fork of a project on GitHub via command line.
25+
26+
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)
27+
28+
Make sure the personal access token has the right `OAuth` scopes for the repo(s)
29+
30+
Use `git config --global --add git-extras.github-personal-access-token <your-personal-access-token>`
31+
32+
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>`
33+
2434
## EXAMPLE
2535

2636
Fork expect.js:

0 commit comments

Comments
 (0)