forked from tj/git-extras
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request tj#563 from lukechilds/improve-fork
git-fork: use ssh remotes if possible
- Loading branch information
Showing
5 changed files
with
43 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 [email protected] exit >/dev/null 2>&1 | ||
ssh_exit_code=$? | ||
if [[ "$ssh_exit_code" = 0 ]] || [[ "$ssh_exit_code" = 1 ]]; then | ||
remote_prefix="[email protected]:" | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters