1

I have two bare repositories.

repo1 - with all the history
repo2 - new, empty one

I want to push all the files from repo1 to repo2, but without the whole history, just the the state from the last commit.

I don't want to touch the history of the repo1 (it's best to assume it's read only). In the new repo I don't want to have any history (including reflogs), so shashing after the push is not an option.

Is this ever possible without creating new, temporary repository?
How can I achieve this?

Sfisioza
  • 3,830
  • 6
  • 42
  • 57

2 Answers2

2

Do the following:

git checkout --orphan temp_branch
git commit -m "initial commit"
git push repo2 temp_branch:master

This will create a temp_branch locally with just a single commit with the current snapshot, and push it to a branch called "master" on repo2.

David Deutsch
  • 17,443
  • 4
  • 47
  • 54
  • checkout in bare repository results in: `fatal: This operation must be run in a work tree` – Sfisioza Feb 08 '16 at 19:24
  • @hagello Both of the repos are bare, without work tree. – Sfisioza Feb 08 '16 at 19:42
  • Ah, I was assuming you were in a non-bare repo. Go ahead and clone repo1 into a non-bare repo; you can pass `--depth 1` to `git clone` (to speed things up) since you are only going to be making an orphan branch anyway. – David Deutsch Feb 08 '16 at 19:51
  • Thanks, but the question is how to do it without creating the new repo :) – Sfisioza Feb 08 '16 at 19:53
0

Assuming that you want to clone the head of masterand assuming that you do not insist on a git push:

# in repo2
# git fetch --depth 1 path_to_repo1 master:master
hagello
  • 2,843
  • 2
  • 27
  • 37