Git bundle and clone as a new repository

The following steps/commands will help to clone a local git repository using git bundle. This is useful when cloning a sample repository or sharing the repository to a peer through email or other channels where git pull/push is not feasible

Navigate to existing repository

cd ~/source_code/my_existing_repository

Create a git bundle from master branch of an existing repository

git bundle create /tmp/my_existing_repository_master.bundle master

Create a new repository from the bundle

git clone -b master /tmp/my_existing_repository_master.bundle ~/source_code/my_new_repository

Navigate to the new repository

cd ~/source_code/my_new_repository

Verify the logs

git --no-pager log --max-count 3

Cleanup the pre-existing origin 

# verify the pre-existing origin before deleting
git remote -v

# delete the pre-existing origin
git remote rm origin

# verify remotes after deleting
git remote -v

Using git archive

There is a git archive command which exports the files in the repo without the history. This will be useful if we are making a simple copy of the files without the history or logs.

git archive --output=./repo-name.zip --format=zip HEAD

Then the file can be unzipped as

unzip ./repo-name.zip -d repo-name

Comments

Popular posts from this blog

JSON with curl and jq

Import self signed in Linux for Chrome / Chromium headless testing

Colima - Drop In replacement for Docker Desktop for Mac and Linux