Tokubara
Tokubara

Reputation: 470

create archive of a git repo with .git

I want to get an archive from a local git repo. The archive should have .git directory and should not have any files that are not under the track of git. It should look like what I get with a git clone command. I don't want to use tar command, because it will include files that are not part of the git repo. I try git archive, but it does not include .git metadata. What can I do?

Upvotes: 0

Views: 671

Answers (2)

Soupy
Soupy

Reputation: 271

The official way to do this is with git bundle. It creates a file with all of the repository information in a single file. Anyone can then use git clone on it to expand it, just like you would with a remote repository.

cd git-repo
# create the bundle file `repo.bundle`:
git bundle repo.bundle --branches --tags

The produced file can then be cloned.

git clone repo.bundle

There are various ways you can configure what goes into the bundle, including which branches and refs are included. The above example includes all of the tags and branches.

You can also update an existing repository with a bundle file. To do this, add it as a remote, and use the normal pull commands:

git remote add bundle ../repo.bundle
git pull bundle

Upvotes: 0

mousetail
mousetail

Reputation: 8010

You can add the extra repo as a remote:

  1. Create a new folder and cd into it
  2. Type git clone [path to your original repo]
  3. Tar the generated folder

This will make a new folder containing only the files checked in to git, and also a .git folder.

Upvotes: 1

Related Questions