diff --git a/bin/git-fork b/bin/git-fork index ba85283f6..dcf634cc7 100755 --- a/bin/git-fork +++ b/bin/git-fork @@ -1,67 +1,120 @@ #!/usr/bin/env bash abort() { - echo "$@" - exit 1 + echo "$@" + exit 1 } -url="$1" -test -z "$url" && url=$(git remote get-url origin 2> /dev/null) && origin=true -# validate repo url -test -z "$url" && abort "github repo needs to be specified as an argument" - -# validate user -echo "Enter your github username" -read -r user -[ -n "$user" ] || abort "git username required" -# 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##*/} -owner=${url%/"$project"} -project=${project%.git} -if [[ $owner == git@* ]]; then - owner=${owner##*:} -else - owner=${owner##*/} -fi - -# validate -[[ -z "$project" || -z "$owner" ]] && abort "github repo needs to be specified as an argument" - -# create fork -if ! curl -qsf \ - -X POST \ - -u "$user:$github_personal_access_token" \ - -H "X-GitHub-OTP: $MFA_CODE" \ - "https://api.github.com/repos/$owner/$project/forks" -then - abort "fork failed" -fi - -echo "Add GitHub remote branch via SSH (you will be prompted to verify the server's credentials)? (y/n)" -read -r use_ssh -# Check if user has ssh configured with GitHub -if [ -n "$use_ssh" ] && ssh -T git@github.com 2>&1 | grep -qi 'success'; then - remote_prefix="git@github.com:" -else - remote_prefix="https://github.com/" -fi - -if [ "$origin" = true ]; then - git remote rename origin upstream - git remote add origin "${remote_prefix}${user}/${project}.git" - git fetch origin -else - # clone forked repo into current dir - git clone "${remote_prefix}${user}/${project}.git" "$project" - # add reference to origin fork so can merge in upstream changes - cd "$project" - git remote add upstream "${remote_prefix}${owner}/${project}.git" - git fetch upstream -fi +print_help() { + echo "Usage: git fork [options] [github-repo-url]" + echo "Options:" + echo " -h, --help Print this help message" + echo " -c, --current Use the URL of the current Git repository as the source" + echo " -t, --token GitHub personal access token" + echo " -d, --target-dir Target directory for cloning the forked repository" +} + +parse_args() { + while getopts ":hct:d:" opt; do + case $opt in + h) + print_help + exit 0 + ;; + c) + origin=true + ;; + t) + github_personal_access_token="$OPTARG" + ;; + d) + target_dir="$OPTARG" + ;; + \?) + abort "Invalid option: -$OPTARG" + ;; + :) + abort "Option -$OPTARG requires an argument" + ;; + esac + done +} + +fork_repository() { + local repo_url=$1 + local user=$2 + local token=$3 + local owner + local project + + # Extract owner and project from repo URL + project=${repo_url##*/} + owner=${repo_url%/"$project"} + project=${project%.git} + if [[ $owner == git@* ]]; then + owner=${owner##*:} + else + owner=${owner##*/} + fi + + # Validate owner and project + [[ -z "$project" || -z "$owner" ]] && abort "GitHub repo URL is not valid" + + # Create fork + if ! curl -qsf \ + -X POST \ + -u "$user:$token" \ + "https://api.github.com/repos/$owner/$project/forks"; then + abort "Fork failed" + fi + + # Add GitHub remote branch via SSH or HTTPS + local remote_prefix + if [ -n "$use_ssh" ] && ssh -T git@github.com 2>&1 | grep -qi 'success'; then + remote_prefix="git@github.com:" + else + remote_prefix="https://github.com/" + fi + + if [ "$origin" = true ]; then + # Rename and add remote for the existing repository + git remote rename origin upstream + git remote add origin "${remote_prefix}${user}/${project}.git" + git fetch origin + else + # Clone forked repo into the specified or default directory + local clone_dir="${target_dir:-$project}" + git clone "${remote_prefix}${user}/${project}.git" "$clone_dir" + # Add reference to the original fork for merging upstream changes + cd "$clone_dir" || exit + git remote add upstream "${remote_prefix}${owner}/${project}.git" + git fetch upstream + fi +} + +main() { + parse_args "$@" + + # Prompt for GitHub username if not provided + echo "Enter your GitHub username:" + read -r user + [ -n "$user" ] || abort "GitHub username is required" + + # Prompt for personal access token if not provided + if [ -z "$github_personal_access_token" ]; then + echo "Enter your GitHub personal access token:" + read -r -s github_personal_access_token + [ -n "$github_personal_access_token" ] || abort "GitHub personal access token is required" + fi + + # Fetch the repository URL + local url=$1 + [ -z "$url" ] && url=$(git remote get-url origin 2>/dev/null) && origin=true + + # Validate repository URL + [ -n "$url" ] || abort "GitHub repo URL needs to be specified as an argument" + + fork_repository "$url" "$user" "$github_personal_access_token" +} + +main "$@" diff --git a/etc/bash_completion.sh b/etc/bash_completion.sh index a5942a4f7..cca305c9e 100644 --- a/etc/bash_completion.sh +++ b/etc/bash_completion.sh @@ -1,161 +1,190 @@ # shellcheck shell=bash # bash completion support for git-extras. -_git_changelog(){ - local s_opts=( '-a' '-l' '-t' '-f' '-s' '-n' '-p' '-x' '-h' '?' ) - local l_opts=( - '--all' - '--list' - '--tag' - '--final-tag' - '--start-tag' - '--start-commit' - '--no-merges' - '--prune-old' - '--stdout' - '--help' - ) - local merged_opts_str="" - merged_opts_str+="$(printf "%s " "${s_opts[@]}")" - merged_opts_str+="$(printf "%s " "${l_opts[@]}")" +_git_changelog() { + local s_opts=('-a' '-l' '-t' '-f' '-s' '-n' '-p' '-x' '-h' '?') + local l_opts=( + '--all' + '--list' + '--tag' + '--final-tag' + '--start-tag' + '--start-commit' + '--no-merges' + '--prune-old' + '--stdout' + '--help' + ) + local merged_opts_str="" + merged_opts_str+="$(printf "%s " "${s_opts[@]}")" + merged_opts_str+="$(printf "%s " "${l_opts[@]}")" - __gitcomp "$merged_opts_str" + __gitcomp "$merged_opts_str" } -_git_authors(){ - __gitcomp "-l --list --no-email" +_git_authors() { + __gitcomp "-l --list --no-email" } -_git_contrib(){ -# git completion function modified from -# https://github.com/markgandolfo/git-bash-completion/blob/master/git-completion.bash - contributors="$(git shortlog -s | cut -f2)" - local all c s=$'\n' IFS=$'\n' - local cur="${COMP_WORDS[COMP_CWORD]}" - for c in $contributors; do - all="$all$c $s" - done - COMPREPLY=($(compgen -W "$all" -- "$cur")) +_git_contrib() { + # git completion function modified from + # https://github.com/markgandolfo/git-bash-completion/blob/master/git-completion.bash + contributors="$(git shortlog -s | cut -f2)" + local all c s=$'\n' IFS=$'\n' + local cur="${COMP_WORDS[COMP_CWORD]}" + for c in $contributors; do + all="$all$c $s" + done + COMPREPLY=($(compgen -W "$all" -- "$cur")) } -_git_count(){ - __gitcomp "--all" +_git_count() { + __gitcomp "--all" } -__git_cp(){ - __git_complete_file +__git_cp() { + __git_complete_file } -_git_delete_branch(){ - __gitcomp "$(__git_heads)" +_git_delete_branch() { + __gitcomp "$(__git_heads)" } -_git_delete_squashed_branches(){ - __gitcomp "$(__git_heads)" +_git_delete_squashed_branches() { + __gitcomp "$(__git_heads)" } -_git_delete_submodule(){ - __gitcomp "$(git submodule status | awk '{print $2}')" +_git_delete_submodule() { + __gitcomp "$(git submodule status | awk '{print $2}')" } -_git_delete_tag(){ - __gitcomp "$(__git_tags)" +_git_delete_tag() { + __gitcomp "$(__git_tags)" } -_git_effort(){ - __git_has_doubledash && return +_git_effort() { + __git_has_doubledash && return - case "$cur" in - --*) - __gitcomp " + case "$cur" in + --*) + __gitcomp " --above $__git_log_common_options $__git_log_shortlog_options " - return - ;; - esac + return + ;; + esac } -_git_extras(){ - __gitcomp "--version update" +_git_extras() { + __gitcomp "--version update" } -__git_extras_workflow(){ - __gitcomp "$(__git_heads | grep -- ^$1/ | sed s/^$1\\///g) finish" +__git_extras_workflow() { + __gitcomp "$(__git_heads | grep -- ^$1/ | sed s/^$1\\///g) finish" } -_git_feature(){ - __git_extras_workflow "feature" +_git_feature() { + __git_extras_workflow "feature" } -_git_graft(){ - __gitcomp "$(__git_heads)" +_git-fork() { + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD - 1]}" + opts="-h --help -c --current -t --token -d --target-dir" + + case "${prev}" in + -t | --token) + return 0 + ;; + -d | --target-dir) + # Complete directories + COMPREPLY=($(compgen -d -- "${cur}")) + return 0 + ;; + *) ;; + esac + + if [[ "${cur}" == -* ]]; then + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + else + # Complete GitHub repo URLs + COMPREPLY=($(compgen -W "$(git ls-remote --get-url --all)" -- ${cur})) + return 0 + fi +} + +_git_graft() { + __gitcomp "$(__git_heads)" } -_git_ignore(){ - case "$cur" in - --*) - __gitcomp "--global --local --private" - return - ;; - -*) - __gitcomp "--global --local --private -g -l -p" - return - ;; - esac +_git_ignore() { + case "$cur" in + --*) + __gitcomp "--global --local --private" + return + ;; + -*) + __gitcomp "--global --local --private -g -l -p" + return + ;; + esac } -_git_missing(){ - # Suggest all known refs - __gitcomp "$(git for-each-ref --format='%(refname:short)')" +_git_missing() { + # Suggest all known refs + __gitcomp "$(git for-each-ref --format='%(refname:short)')" } -_git_psykorebase(){ - __gitcomp "$(__git_heads) --continue --no-ff" +_git_psykorebase() { + __gitcomp "$(__git_heads) --continue --no-ff" } -_git_reauthor(){ - local prev="${COMP_WORDS[COMP_CWORD-1]}" - local comp +_git_reauthor() { + local prev="${COMP_WORDS[COMP_CWORD - 1]}" + local comp - if [[ "${prev}" == '--type' ]] || [[ "${prev}" == '-t' ]]; then - comp='author committer full' - else - comp='--all --correct-email --correct-name --old-email --type --use-config' - fi + if [[ "${prev}" == '--type' ]] || [[ "${prev}" == '-t' ]]; then + comp='author committer full' + else + comp='--all --correct-email --correct-name --old-email --type --use-config' + fi - __gitcomp "${comp}" + __gitcomp "${comp}" } -_git_scp(){ - __git_complete_remote_or_refspec +_git_scp() { + __git_complete_remote_or_refspec } -_git_stamp(){ - __gitcomp '--replace -r' +_git_stamp() { + __gitcomp '--replace -r' } -_git_rscp(){ - __git_complete_remote_or_refspec +_git_rscp() { + __git_complete_remote_or_refspec } -_git_squash(){ - __gitcomp "$(__git_heads)" +_git_squash() { + __gitcomp "$(__git_heads)" } -_git_undo(){ - __gitcomp "--hard --soft -h -s" +_git_undo() { + __gitcomp "--hard --soft -h -s" } -_git_info(){ - __gitcomp "--color -c --no-config" +_git_info() { + __gitcomp "--color -c --no-config" } -_git_browse(){ - __git_complete_remote_or_refspec +_git_browse() { + __git_complete_remote_or_refspec } -_git_browse_ci(){ - __git_complete_remote_or_refspec +_git_browse_ci() { + __git_complete_remote_or_refspec } diff --git a/etc/git-extras-completion.zsh b/etc/git-extras-completion.zsh index f5fd387d1..8444970b2 100644 --- a/etc/git-extras-completion.zsh +++ b/etc/git-extras-completion.zsh @@ -247,6 +247,25 @@ _git-feature() { '(--remote -r)'{--remote,-r}'[setup remote tracking branch]' } +_git-fork() { + local curcontext="$curcontext" state line + typeset -A opt_args + + _arguments \ + '1: :->url' \ + '-h[--help]'{-h,--help}'[Print help message]' \ + '-c[--current]'{-c,--current}'[Use the URL of the current Git repository as the source]' \ + '-t[--token]:GitHub personal access token:'{-t,--token}'[Specify the GitHub personal access token]' \ + '-d[--target-dir]:Target directory:'{-d,--target-dir}'[Specify the target directory for cloning the forked repository]' \ + && return 0 + + case "$state" in + url) + _urls + ;; + esac +} + _git-graft() { _arguments \ ':src-branch-name:__gitex_branch_names' \ diff --git a/etc/git-extras.fish b/etc/git-extras.fish index 17bcdfa80..96ba0d5d3 100644 --- a/etc/git-extras.fish +++ b/etc/git-extras.fish @@ -70,20 +70,20 @@ set __fish_git_extras_commands \ "unlock:Unlock a file excluded from version control" # completion for git-extras itself -complete -c git -f -n '__fish_git_needs_command' -a 'extras' -d 'GIT utilities: repo summary, repl, changelog population, and more' +complete -c git -f -n __fish_git_needs_command -a extras -d 'GIT utilities: repo summary, repl, changelog population, and more' complete -c git -f -n '__fish_git_using_command extras' -s h -l help -d 'Show the help message, can be used for any git-extras commands' complete -c git -f -n '__fish_git_using_command extras' -s v -l version -d 'Show git-extras version number' -complete -c git -f -n '__fish_git_using_command extras; and not contains -- update (commandline -opc)' -a "update" -d 'Self update' +complete -c git -f -n '__fish_git_using_command extras; and not contains -- update (commandline -opc)' -a update -d 'Self update' # completion for git-extras provided commands set __fish_git_extras_commands (printf -- '%s\n' $__fish_git_extras_commands | sed 's/:/\textras:/' | string collect | string escape) -complete -c git -n '__fish_git_needs_command' -a "$__fish_git_extras_commands" +complete -c git -n __fish_git_needs_command -a "$__fish_git_extras_commands" # authors complete -c git -f -n '__fish_git_using_command authors' -s l -l list -d 'show authors' complete -c git -f -n '__fish_git_using_command authors' -l no-email -d 'without email' # bulk -complete -c git -n '__fish_git_using_command bulk' -s a -d 'Run a git command on all workspaces and their repositories' -complete -c git -n '__fish_git_using_command bulk' -s g -d 'Ask the user for confirmation on every execution' +complete -c git -n '__fish_git_using_command bulk' -s a -d 'Run a git command on all workspaces and their repositories' +complete -c git -n '__fish_git_using_command bulk' -s g -d 'Ask the user for confirmation on every execution' complete -c git -x -n '__fish_git_using_command bulk' -s w -d 'Run on specified workspace' complete -c git -x -n '__fish_git_using_command bulk' -l addworkspace -d 'Register a workspace for builk operations' complete -c git -x -n '__fish_git_using_command bulk; and contains addworkspace (commandline -opc)' -l addworkspace -d 'the URL or file with URLs to be added' @@ -118,18 +118,60 @@ complete -c git -x -n "__fish_git_using_command delete-tag" -a '(__fish_git for- complete -c git -f -n '__fish_git_using_command effort' -l above -d 'ignore file with less than x commits' # feature complete -c git -x -n '__fish_git_using_command feature' -s a -l alias -d 'use branch_prefix instead of feature' -complete -c git -f -n '__fish_git_using_command feature; and not contains -- finish (commandline -opc)' -a "finish" -d 'merge and delete the feature branch' +complete -c git -f -n '__fish_git_using_command feature; and not contains -- finish (commandline -opc)' -a finish -d 'merge and delete the feature branch' complete -c git -f -n '__fish_git_using_command feature; and contains -- finish (commandline -opc)' -l squash -d 'Run a squash merge' complete -c git -x -n '__fish_git_using_command feature; and contains -- finish (commandline -opc)' -a '(__fish_git for-each-ref --format="%(refname)" 2>/dev/null | grep "refs/heads/feature")' -d 'name of feature branch' complete -c git -x -n '__fish_git_using_command feature; and not contains -- finish (commandline -opc)' -s r -l remote -a '(__fish_git_unique_remote_branches)' -d 'Setup a remote tracking branch' +# fork +function __fish_git_fork_get_remotes + git remote -v | awk '{print $2}' | cut -d / -f 3 +end + +function __fish_git_fork + set -l cur (commandline -ct) + set -l prev (commandline -ct -1) + set -l opts '-h --help -c --current -t --token -d --target-dir' + + switch "$prev" + case -t --token + return + + case -d --target-dir + # Complete directories + set -l completions (commandline -e -o dirnames) + set -l dir (commandline -co) + for completion in $completions + echo $dir/$completion + end + return + + case '*' + + # Complete options + set -l completions (commandline -pco) + for completion in $completions + echo $completion + end + return + end + + if string match -q -r -- '-.*' "$cur" + echo $opts + else + # Complete GitHub repo URLs + __fish_git_fork_get_remotes + end +end + +complete -f -c git-fork -a "(__fish_git_fork)" -d 'Fork a repo on GitHub' # graft -complete -c git -x -n '__fish_git_using_command graft' -s r -l remote -a '(__fish_git_branches)' -d 'src-branch-name' -complete -c git -x -n '__fish_git_using_command graft' -s r -l remote -a '(__fish_git_branches)' -d 'dest-branch-name' +complete -c git -x -n '__fish_git_using_command graft' -s r -l remote -a '(__fish_git_branches)' -d src-branch-name +complete -c git -x -n '__fish_git_using_command graft' -s r -l remote -a '(__fish_git_branches)' -d dest-branch-name # guilt complete -c git -f -n '__fish_git_using_command guilt' -s w -l ignore-whitespace -d 'ignore whitespace only changes' complete -c git -f -n '__fish_git_using_command guilt' -s e -l email -d 'display author emails instead of names' complete -c git -f -n '__fish_git_using_command guilt' -s d -l debug -d 'output debug information' -complete -c git -f -n '__fish_git_using_command guilt' -s h -d 'output usage information' +complete -c git -f -n '__fish_git_using_command guilt' -s h -d 'output usage information' # ignore complete -c git -f -n '__fish_git_using_command ignore' -s l -l local -d 'show local gitignore' complete -c git -f -n '__fish_git_using_command ignore' -s g -l global -d 'show global gitignore' @@ -148,7 +190,7 @@ complete -c git -x -n '__fish_git_using_command ignore-io' -s s -l search -d 'se complete -c git -x -n '__fish_git_using_command ignore-io' -s t -l show-update-time -d 'Show the last modified time of ~/.gi_list' complete -c git -x -n '__fish_git_using_command ignore-io' -s u -l update -d 'Update ~/.gi_list' # merge-into -complete -c git -n '__fish_git_using_command merge-into' -l ff-only -d 'merge only fast-forward' +complete -c git -n '__fish_git_using_command merge-into' -l ff-only -d 'merge only fast-forward' complete -c git -x -n '__fish_git_using_command merge-into' -a '(__fish_git_branches)' # missing complete -c git -x -n '__fish_git_using_command missing' -a '(__fish_git_branches)' @@ -162,16 +204,16 @@ complete -c git -x -n '__fish_git_using_command standup' -s a -d 'Specify the au complete -c git -x -n '__fish_git_using_command standup' -s m -d 'The depth of recursive directory search' complete -c git -x -n '__fish_git_using_command standup' -s d -d 'Show history since N days ago' complete -c git -x -n '__fish_git_using_command standup' -s D -d 'Specify the date format displayed in commit history' -complete -c git -n '__fish_git_using_command standup' -s f -d 'Fetch commits before showing history' -complete -c git -n '__fish_git_using_command standup' -s g -d 'Display GPG signed info' -complete -c git -n '__fish_git_using_command standup' -s h -l help -d 'Display help message' -complete -c git -n '__fish_git_using_command standup' -s L -d 'Enable the inclusion of symbolic links' -complete -c git -n '__fish_git_using_command standup' -s B -d 'Display the commits in branch group' +complete -c git -n '__fish_git_using_command standup' -s f -d 'Fetch commits before showing history' +complete -c git -n '__fish_git_using_command standup' -s g -d 'Display GPG signed info' +complete -c git -n '__fish_git_using_command standup' -s h -l help -d 'Display help message' +complete -c git -n '__fish_git_using_command standup' -s L -d 'Enable the inclusion of symbolic links' +complete -c git -n '__fish_git_using_command standup' -s B -d 'Display the commits in branch group' complete -c git -x -n '__fish_git_using_command standup' -s n -d 'Limit the number of commits displayed per group' # summary -complete -c git -n '__fish_git_using_command summary' -l line -d 'summarize with lines rather than commits' -complete -c git -n '__fish_git_using_command summary' -l dedup-by-email -d 'remove duplicate users by the email address' -complete -c git -n '__fish_git_using_command summary' -l no-merges -d 'exclude merge commits' +complete -c git -n '__fish_git_using_command summary' -l line -d 'summarize with lines rather than commits' +complete -c git -n '__fish_git_using_command summary' -l dedup-by-email -d 'remove duplicate users by the email address' +complete -c git -n '__fish_git_using_command summary' -l no-merges -d 'exclude merge commits' # release complete -c git -x -n '__fish_git_using_command release' -s c -d 'Generates/populates the changelog with all commit message since the last tag' complete -c git -x -n '__fish_git_using_command release' -s r -d 'The "remote" repository that is destination of a push operation' @@ -183,5 +225,3 @@ complete -c git -x -n '__fish_git_using_command release' -l no-empty-commit -d ' # undo complete -c git -x -n '__fish_git_using_command undo' -s s -l soft -d 'only rolls back the commit but changes remain un-staged' complete -c git -x -n '__fish_git_using_command undo' -s h -l hard -d 'wipes your commit(s)' - - diff --git a/man/git-fork.1 b/man/git-fork.1 index e259745e7..06ef0a8ab 100644 --- a/man/git-fork.1 +++ b/man/git-fork.1 @@ -1,123 +1,93 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "GIT\-FORK" "1" "October 2017" "" "Git Extras" -. +.\" generated with Ronn-NG/v0.9.1 +.\" http://github.com/apjanke/ronn-ng/tree/0.9.1 +.TH "GIT\-FORK" "1" "June 2023" "" .SH "NAME" \fBgit\-fork\fR \- Fork a repo on github -. .SH "SYNOPSIS" \fBgit\-fork\fR [] -. .SH "DESCRIPTION" -If a github repo url is given, fork the repo\. Like clone but forks first\. -. +If a GitHub repo URL is given, the command forks the specified repository\. It performs the following actions: .IP "1." 4 -forks the repo on github -. +Forks the repo on GitHub\. .IP "2." 4 -clones the repo into the current dir -. +Clones the repo into the current directory or the one specified with \fBd\fR or \fB\-\-target\-dir\fR\. .IP "3." 4 -adds the original repo as a remote called \fBupstream\fR -. +Adds the original repo as a remote called \fBupstream\fR\. .IP "" 0 -. .P -If a url is not given and the current dir is a github repo, fork the repo\. -. +If a URL is not provided and the current directory is a GitHub repository, the command forks the current repo\. It performs the following actions: .IP "1." 4 -forks the current repo -. +Forks the current repo .IP "2." 4 -rename the \fBorigin\fR remote repo to \fBupstream\fR -. +Renames the \fBorigin\fR remote repo to \fBupstream\fR .IP "3." 4 -adds the forked repo as a remote called \fBorigin\fR -. +Adds the forked repo as a remote called \fBorigin\fR .IP "" 0 -. .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\. -. +Remotes will use SSH if you have it configured with GitHub\. Otherwise, HTTPS will be used\. .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 -. +To create a fork of a project on GitHub via the command line, a personal access token is required\. .P -Make sure the personal access token has the right \fBOAuth\fR scopes for the repo(s) -. +The token is used for making the API call to create the fork on GitHub\. .P -Use \fBgit config \-\-global \-\-add git\-extras\.github\-personal\-access\-token \fR -. +Refer to the GitHub API Documentation \fIhttps://docs\.github\.com/en/rest/reference/repos#forks\fR for more information\. .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" +Make sure that the personal access token has the necessary OAuth scopes for the repository\. +.P +You can configure the token by issuing the command: +.P +\fBgit config \-\-global \-\-add git\-extras\.github\-personal\-access\-token \fR\. +.P +If you have multiple GitHub accounts and need to override the global token for a specific repository, use the command: +.P +\fBgit config git\-extras\.github\-personal\-access\-token \fR\. +.SH "OPTIONS" +The following options are available: +.IP "\[ci]" 4 +\fB\-h\fR, \fB\-\-help\fR: Print the help message and usage information\. +.IP "\[ci]" 4 +\fB\-c\fR, \fB\-\-current\fR: Use the URL of the current Git repository as the source\. +.IP "\[ci]" 4 +\fB\-t\fR, \fB\-\-token \fR: Specify the GitHub personal access token\. +.IP "\[ci]" 4 +\fB\-d\fR, \fB\-\-target\-dir \fR: Specify the target directory for cloning the forked repository\. +.IP "" 0 +.SH "EXAMPLES" Fork expect\.js: -. .IP "" 4 -. .nf - $ git fork https://github\.com/LearnBoost/expect\.js -. .fi -. .IP "" 0 -. .P or just: -. .IP "" 4 -. .nf - $ git fork LearnBoost/expect\.js -. .fi -. .IP "" 0 -. .P -Then: -. +Then, the forked repository will be cloned into the \fBexpect\.js\fR directory locally\. You can navigate to the directory and check the remotes: .IP "" 4 -. .nf - -$ \.\.\.\.\. - $ cd expect\.js && git remote \-v origin git@github\.com:/expect\.js (fetch) origin git@github\.com:/expect\.js (push) upstream git@github\.com:LearnBoost/expect\.js (fetch) upstream git@github\.com:LearnBoost/expect\.js (push) -. .fi -. .IP "" 0 -. .P If the current dir is a clone of expect\.js, this has the same effect: -. .IP "" 4 -. .nf - $ git fork -. .fi -. .IP "" 0 -. -.SH "AUTHOR" -Written by Andrew Griffiths <\fImail@andrewgriffithsonline\.com\fR> -. +.SH "AUTHORS" +Written by Andrew Griffiths <\fImail@andrewgriffithsonline\.com\fR> Co\-authored by Marcelina Hołub <\fImholub@tutanota\.com\fR> .SH "REPORTING BUGS" <\fIhttps://github\.com/tj/git\-extras/issues\fR> -. .SH "SEE ALSO" <\fIhttps://github\.com/tj/git\-extras\fR> diff --git a/man/git-fork.1.html b/man/git-fork.1.html new file mode 100644 index 000000000..cfaf3e1d0 --- /dev/null +++ b/man/git-fork.1.html @@ -0,0 +1,184 @@ + + + + + + git-fork(1) - Fork a repo on github + + + + +
+ + + +
    +
  1. git-fork(1)
  2. +
  3. +
  4. git-fork(1)
  5. +
+ + + +

NAME

+

+ git-fork - Fork a repo on github +

+

SYNOPSIS

+ +

git-fork [<github-repo-url>]

+ +

DESCRIPTION

+ +

If a GitHub repo URL is given, the command forks the specified repository. It performs the following actions:

+ +
    +
  1. Forks the repo on GitHub.
  2. +
  3. Clones the repo into the current directory or the one specified with d or --target-dir.
  4. +
  5. Adds the original repo as a remote called upstream.
  6. +
+ +

If a URL is not provided and the current directory is a GitHub repository, the command forks the current repo. + It performs the following actions:

+ +
    +
  1. Forks the current repo
  2. +
  3. Renames the origin remote repo to upstream +
  4. +
  5. Adds the forked repo as a remote called origin +
  6. +
+ +

Remotes will use SSH if you have it configured with GitHub. Otherwise, HTTPS will be used.

+ +

To create a fork of a project on GitHub via the command line, a personal access token is required.

+ +

The token is used for making the API call to create the fork on GitHub.

+ +

Refer to the GitHub API Documentation for more information.

+ +

Make sure that the personal access token has the necessary OAuth scopes for the repository.

+ +

You can configure the token by issuing the command:

+ +

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

+ +

If you have multiple GitHub accounts and need to override the global token for a specific repository, use the command:

+ +

git config git-extras.github-personal-access-token <other-acc-personal-access-token>.

+ +

OPTIONS

+ +

The following options are available:

+ +
    +
  • +-h, --help: Print the help message and usage information.
  • +
  • +-c, --current: Use the URL of the current Git repository as the source.
  • +
  • +-t, --token <token>: Specify the GitHub personal access token.
  • +
  • +-d, --target-dir <directory>: Specify the target directory for cloning the forked repository.
  • +
+ +

EXAMPLES

+ +

Fork expect.js:

+ +
$ git fork https://github.com/LearnBoost/expect.js
+
+ +

or just:

+ +
$ git fork LearnBoost/expect.js
+
+ +

Then, the forked repository will be cloned into the expect.js directory locally. You can navigate to the directory and check the remotes:

+ +
$ cd expect.js && git remote -v
+
+  origin          git@github.com:<user>/expect.js (fetch)
+  origin          git@github.com:<user>/expect.js (push)
+  upstream        git@github.com:LearnBoost/expect.js (fetch)
+  upstream        git@github.com:LearnBoost/expect.js (push)
+
+ +

If the current dir is a clone of expect.js, this has the same effect:

+ +
$ git fork
+
+ +

AUTHORS

+ +

Written by Andrew Griffiths <mail@andrewgriffithsonline.com> +Co-authored by Marcelina Hołub <mholub@tutanota.com>

+ +

REPORTING BUGS

+ +

<https://github.com/tj/git-extras/issues>

+ +

SEE ALSO

+ +

<https://github.com/tj/git-extras>

+ +
    +
  1. +
  2. June 2023
  3. +
  4. git-fork(1)
  5. +
+ +
+ + diff --git a/man/git-fork.md b/man/git-fork.md index 701ac87a9..fb6e74367 100644 --- a/man/git-fork.md +++ b/man/git-fork.md @@ -7,31 +7,47 @@ git-fork(1) -- Fork a repo on github ## DESCRIPTION - If a github repo url is given, fork the repo. Like clone but forks first. + If a GitHub repo URL is given, the command forks the specified repository. It performs the following actions: - 1. forks the repo on github - 2. clones the repo into the current dir - 3. adds the original repo as a remote called `upstream` + 1. Forks the repo on GitHub. + 2. Clones the repo into the current directory or the one specified with `d` or `--target-dir`. + 3. Adds the original repo as a remote called `upstream`. - If a url is not given and the current dir is a github repo, fork the repo. + If a URL is not provided and the current directory is a GitHub repository, the command forks the current repo. + It performs the following actions: - 1. forks the current repo - 2. rename the `origin` remote repo to `upstream` - 3. adds the forked repo as a remote called `origin` + 1. Forks the current repo + 2. Renames the `origin` remote repo to `upstream` + 3. Adds the forked repo as a remote called `origin` - Remotes will use ssh if you have it configured with GitHub, if not, https will be used. + Remotes will use SSH if you have it configured with GitHub. Otherwise, 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 ` + To create a fork of a project on GitHub via the command line, a personal access token is required. -## EXAMPLE + The token is used for making the API call to create the fork on GitHub. + + Refer to the [GitHub API Documentation](https://docs.github.com/en/rest/reference/repos#forks) for more information. + + Make sure that the personal access token has the necessary OAuth scopes for the repository. + + You can configure the token by issuing the command: + + `git config --global --add git-extras.github-personal-access-token `. + + If you have multiple GitHub accounts and need to override the global token for a specific repository, use the command: + + `git config git-extras.github-personal-access-token `. + +## OPTIONS + +The following options are available: + +- `-h`, `--help`: Print the help message and usage information. +- `-c`, `--current`: Use the URL of the current Git repository as the source. +- `-t`, `--token `: Specify the GitHub personal access token. +- `-d`, `--target-dir `: Specify the target directory for cloning the forked repository. + +## EXAMPLES Fork expect.js: @@ -41,9 +57,7 @@ git-fork(1) -- Fork a repo on github $ git fork LearnBoost/expect.js - Then: - - $ ..... + Then, the forked repository will be cloned into the `expect.js` directory locally. You can navigate to the directory and check the remotes: $ cd expect.js && git remote -v @@ -57,9 +71,10 @@ git-fork(1) -- Fork a repo on github $ git fork -## AUTHOR +## AUTHORS Written by Andrew Griffiths <> +Co-authored by Marcelina Hołub <> ## REPORTING BUGS