From c87d59346b73298de07d2c3472480f883454152c Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Tue, 2 Aug 2016 18:23:21 +0100 Subject: [PATCH 1/3] Set fork remotes using ssh if available --- bin/git-fork | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/bin/git-fork b/bin/git-fork index 64f6a9c8a..cd39fdd91 100755 --- a/bin/git-fork +++ b/bin/git-fork @@ -34,16 +34,25 @@ fi curl -X POST -u "$user" "https://api.github.com/repos/$owner/$project/forks" [ $? = 0 ] || abort "fork failed" +# Check if user has ssh configured with GitHub +ssh -o BatchMode=yes git@github.com exit >/dev/null 2>&1 +ssh_exit_code=$? +if [[ "$ssh_exit_code" = 0 ]] || [[ "$ssh_exit_code" = 1 ]]; 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 "https://github.com/$user/$project" + git remote add origin "$remote_prefix$user/$project" git fetch origin else # clone forked repo into current dir - git clone "https://github.com/$user/$project" "$project" + git clone "$remote_prefix$user/$project" "$project" # add reference to origin fork so can merge in upstream changes cd "$project" - git remote add upstream "https://github.com/$owner/$project" + git remote add upstream "$remote_prefix$owner/$project" git fetch upstream fi From ca78ac71ba136e2512d2ce6538975a8a1a389fa9 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Wed, 3 Aug 2016 13:10:18 +0100 Subject: [PATCH 2/3] Update docs to reflect new git-fork behaviour --- Commands.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Commands.md b/Commands.md index 90ddc9895..5048c842c 100644 --- a/Commands.md +++ b/Commands.md @@ -196,7 +196,7 @@ project : git-extras ## git line-summary - WARNING: git line-summary has been replaced by git summary --line and will be removed in a future release. + WARNING: git line-summary has been replaced by git summary --line and will be removed in a future release. ## git effort @@ -215,7 +215,7 @@ $ git effort --above 5 ``` If you wish to see only the commits in the last month you may use `--since` (it supports the same syntax like `git log --since`): - + ``` $ git effort --since='last month' ``` @@ -319,7 +319,7 @@ Does the following: - forks the repo (prompts for github username and pass) - clones the repo into the current directory - adds the original repo as a remote so can track upstream changes -- all remotes refs use git over ssh +- all remotes refs use git over ssh if configured, otherwise https will be used ```Shell @@ -427,7 +427,7 @@ To show just the global or just the local file's contents, you can use the follo * `-g` or `--global` to show just the global file * `-l` or `--local` to show just the local file - + ```bash $ git ignore -g Global gitignore: /Users/foo/.gitignore_global @@ -462,7 +462,7 @@ $ git ignore-io vim .netrwhist *~ ``` - + To export it to `.gitignore` file you can use the following options: * `-a` or `--append` to append the result to `.gitignore` @@ -476,7 +476,7 @@ For efficiency, `git ignore-io` store all available types at `~/.gi_list`. To list all the available types: * `-l` or `-L` : These two options will show the list in different format. Just try it. - + You can also search type from the list by: * `-s ` or `--search ` @@ -804,7 +804,7 @@ Set up a git repository (if one doesn't exist), add all files, and make an initi A convenient way to copy files from the current working tree to the working directory of a remote repository. If a `...` is provided, only files that has changed within the commit range will be copied. -Internally this script uses `rsync` and not `scp` as the name suggests. +Internally this script uses `rsync` and not `scp` as the name suggests. `git-rscp` - The reverse of `git-scp`. Copies specific files from the working directory of a remote repository to the current working directory. @@ -1078,7 +1078,7 @@ Create pull request via commandline. ## git rebase-patch -Given you have a patch that doesn´t apply to the current HEAD, but you know it applied to some commit in the past, +Given you have a patch that doesn´t apply to the current HEAD, but you know it applied to some commit in the past, `git rebase-patch` will help you find that commit and do a rebase. For example, @@ -1108,4 +1108,3 @@ Sync local branch with origin/master ```bash $ git sync origin master ``` - From 93ae8fd81e675d4d1df2dbaae258cd6e2282cfc7 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Wed, 3 Aug 2016 18:30:50 +0100 Subject: [PATCH 3/3] Update git-fork man page --- man/git-fork.1 | 13 ++++++++----- man/git-fork.html | 14 ++++++++------ man/git-fork.md | 12 +++++++----- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/man/git-fork.1 b/man/git-fork.1 index e9e80430a..e3c40685e 100644 --- a/man/git-fork.1 +++ b/man/git-fork.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "GIT\-FORK" "1" "July 2016" "" "Git Extras" +.TH "GIT\-FORK" "1" "August 2016" "" "Git Extras" . .SH "NAME" \fBgit\-fork\fR \- Fork a repo on github @@ -37,6 +37,9 @@ 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\. +. .SH "EXAMPLE" Fork expect\.js: . @@ -74,10 +77,10 @@ $ \.\. $ cd expect\.js && git remote \-v - origin https://github\.com//expect\.js (fetch) - origin https://github\.com//expect\.js (push) - upstream https://github\.com/LearnBoost/expect\.js (fetch) - upstream https://github\.com/LearnBoost/expect\.js (push) + 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 . diff --git a/man/git-fork.html b/man/git-fork.html index 268c6c071..06b5b4443 100644 --- a/man/git-fork.html +++ b/man/git-fork.html @@ -97,6 +97,8 @@

DESCRIPTION

+

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

+

EXAMPLE

Fork expect.js:

@@ -115,10 +117,10 @@

EXAMPLE

$ cd expect.js && git remote -v - origin https://github.com/<user>/expect.js (fetch) - origin https://github.com/<user>/expect.js (push) - upstream https://github.com/LearnBoost/expect.js (fetch) - upstream https://github.com/LearnBoost/expect.js (push) + 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:

@@ -128,7 +130,7 @@

EXAMPLE

AUTHOR

-

Written by Andrew Griffiths <mail@andrewgriffithsonline.com>

+

Written by Andrew Griffiths <mail@andrewgriffithsonline.com>

REPORTING BUGS

@@ -141,7 +143,7 @@

SEE ALSO

  1. -
  2. July 2016
  3. +
  4. August 2016
  5. git-fork(1)
diff --git a/man/git-fork.md b/man/git-fork.md index e651b2bba..890c5d963 100644 --- a/man/git-fork.md +++ b/man/git-fork.md @@ -16,9 +16,11 @@ git-fork(1) -- Fork a repo on github If a url is not given and the current dir is a github repo, fork the repo. 1. forks the current repo - 3. rename the `origin` remote repo to `upstream` + 2. rename 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. + ## EXAMPLE Fork expect.js: @@ -35,10 +37,10 @@ git-fork(1) -- Fork a repo on github $ cd expect.js && git remote -v - origin https://github.com//expect.js (fetch) - origin https://github.com//expect.js (push) - upstream https://github.com/LearnBoost/expect.js (fetch) - upstream https://github.com/LearnBoost/expect.js (push) + 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) If the current dir is a clone of expect.js, this has the same effect: