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
git remote -v
# delete the pre-existing origin
git remote rm origin
# verify remotes after deleting
git remote -v
Navigate to existing repository
cd ~/source_code/my_existing_repositoryCreate a git bundle from master branch of an existing repository
git bundle create /tmp/my_existing_repository_master.bundle masterCreate a new repository from the bundle
git clone -b master /tmp/my_existing_repository_master.bundle ~/source_code/my_new_repositoryNavigate to the new repository
cd ~/source_code/my_new_repositoryVerify the logs
git --no-pager log --max-count 3Cleanup the pre-existing origin
# verify the pre-existing origin before deletinggit 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
Post a Comment