Skip to content

Commit

Permalink
Merge pull request tj#357 from imsky/merge-repo
Browse files Browse the repository at this point in the history
git-merge-repo
  • Loading branch information
hemanth committed Apr 20, 2015
2 parents d6c155c + 05b0a5d commit 3055a66
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 0 deletions.
25 changes: 25 additions & 0 deletions bin/git-merge-repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

repo=$1
branch=$2
prefix=$3
flat=0

if test $prefix = "."; then
prefix=$(mktemp -u 'git-merge-repo.XXXXXXX')
flat=1
fi

git subtree add -P "$prefix" "$repo" "$branch" "${@:4}"

message=$(git log -1 --pretty=%B)

if test $flat -eq 1; then
git stash -u
mv -i $prefix/* ./
git undo
git add .
git commit -am "$message"
git stash apply
rm -drf $prefix
fi
51 changes: 51 additions & 0 deletions man/git-merge-repo.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-MERGE\-REPO" "1" "April 2015" "" "Git Extras"
.
.SH "NAME"
\fBgit\-merge\-repo\fR \- Merge two repo histories
.
.SH "SYNOPSIS"
\fBgit\-merge\-repo\fR <repo> <branch> <directory> [\-\-squash]
.
.SH "DESCRIPTION"
Merges a repository\'s history with the current repository, inside a specified directory\.
.
.P
Optional \fB\-\-squash\fR flag skips the full history and generates only one commit for the merge\.
.
.SH "EXAMPLES"
Merges a local repo\'s \fBfrontend\fR branch into the current repo\'s \fBweb\fR folder:
.
.IP "" 4
.
.nf

$ git merge\-repo \.\./app/\.git frontend web
.
.fi
.
.IP "" 0
.
.P
Merges a remote repo\'s \fBmaster\fR branch into the current repo\'s folder:
.
.IP "" 4
.
.nf

$ git merge\-repo git@github\.com:tj/git\-extras\.git master \.
.
.fi
.
.IP "" 0
.
.SH "AUTHOR"
Written by Ivan Malopinsky <\fIhello@imsky\.co\fR>
.
.SH "REPORTING BUGS"
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
.
.SH "SEE ALSO"
<\fIhttps://github\.com/tj/git\-extras\fR>
119 changes: 119 additions & 0 deletions man/git-merge-repo.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions man/git-merge-repo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
git-merge-repo(1) -- Merge two repo histories
=============================================

## SYNOPSIS

`git-merge-repo` &lt;repo&gt; &lt;branch&gt; &lt;directory&gt; [--squash]

## DESCRIPTION

Merges a repository's history with the current repository, inside a specified directory.

Optional `--squash` flag skips the full history and generates only one commit for the merge.

## EXAMPLES

Merges a local repo's `frontend` branch into the current repo's `web` folder:

$ git merge-repo ../app/.git frontend web

Merges a remote repo's `master` branch into the current repo's folder:

$ git merge-repo [email protected]:tj/git-extras.git master .

## AUTHOR

Written by Ivan Malopinsky &lt;<[email protected]>&gt;

## REPORTING BUGS

&lt;<https://github.com/tj/git-extras/issues>&gt;

## SEE ALSO

&lt;<https://github.com/tj/git-extras>&gt;

0 comments on commit 3055a66

Please sign in to comment.