diff --git a/bin/git-fork b/bin/git-fork index a1d93ca8a..1294254ae 100755 --- a/bin/git-fork +++ b/bin/git-fork @@ -7,7 +7,7 @@ abort() { url="$1" -test -z "$url" && url=`git remote get-url origin 2> /dev/null` +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" @@ -34,10 +34,15 @@ fi curl -X POST -u "$user" "https://api.github.com/repos/$owner/$project/forks" [ $? = 0 ] || abort "fork failed" -# clone forked repo into current dir -git clone "https://github.com/$user/$project" "$project" +if [ "$origin" = true ]; then + git remote rename origin upstream + git remote add origin "https://github.com/$user/$project" +else + # clone forked repo into current dir + git clone "https://github.com/$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 fetch upstream + # add reference to origin fork so can merge in upstream changes + cd "$project" + git remote add upstream "https://github.com/$owner/$project" + git fetch upstream +fi diff --git a/man/git-fork.1 b/man/git-fork.1 index ed46a505c..c27cddb5d 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" "December 2015" "" "" +.TH "GIT\-FORK" "1" "July 2016" "" "Git Extras" . .SH "NAME" \fBgit\-fork\fR \- Fork a repo on github @@ -10,7 +10,7 @@ \fBgit\-fork\fR [] . .SH "DESCRIPTION" -Fork the given github repo\. Like clone but forks first\. +If a github repo url is given, fork the repo\. Like clone but forks first\. . .IP "1." 4 forks the repo on github @@ -23,6 +23,20 @@ adds the original repo as a remote called upstream . .IP "" 0 . +.P +If a url is not given and the current dir is a github repo, fork the repo\. +. +.IP "1." 4 +forks the current repo +. +.IP "2." 4 +rename the \'origin\' remote repo to \'upstream\' +. +.IP "3." 4 +adds the forked repo as a remote called origin +. +.IP "" 0 +. .SH "EXAMPLE" Fork expect\.js: . @@ -69,6 +83,19 @@ $ cd expect\.js && git remote \-v . .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> . diff --git a/man/git-fork.html b/man/git-fork.html index 4d8624bf8..e69de29bb 100644 --- a/man/git-fork.html +++ b/man/git-fork.html @@ -1,136 +0,0 @@ - - - - - - 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

- -

Fork the given github repo. Like clone but forks first.

- -
    -
  1. forks the repo on github
  2. -
  3. clones the repo into the current dir
  4. -
  5. adds the original repo as a remote called upstream
  6. -
- - -

EXAMPLE

- -

Fork expect.js:

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

or just:

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

Then:

- -
$ ..<forks into your github profile and clones repo locally to expect.js dir>...
-
-$ 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)
-
- -

AUTHOR

- -

Written by Andrew Griffiths <mail@andrewgriffithsonline.com>

- -

REPORTING BUGS

- -

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

- -

SEE ALSO

- -

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

- - -
    -
  1. -
  2. December 2015
  3. -
  4. git-fork(1)
  5. -
- -
- - diff --git a/man/git-fork.md b/man/git-fork.md index 8c0a63b7e..523a1d5d9 100644 --- a/man/git-fork.md +++ b/man/git-fork.md @@ -7,12 +7,18 @@ git-fork(1) -- Fork a repo on github ## DESCRIPTION - Fork the given github repo. Like clone but forks first. + If a github repo url is given, fork the repo. Like clone but forks first. 1. forks the repo on github 2. clones the repo into the current 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. + + 1. forks the current repo + 3. rename the 'origin' remote repo to 'upstream' + 3. adds the forked repo as a remote called origin + ## EXAMPLE Fork expect.js: @@ -34,6 +40,10 @@ git-fork(1) -- Fork a repo on github upstream https://github.com/LearnBoost/expect.js (fetch) upstream https://github.com/LearnBoost/expect.js (push) + If the current dir is a clone of expect.js, this has the same effect: + + $ git fork + ## AUTHOR