How to Use “git-archive” Command in Git
Sometimes, Git users want to send a large amount of data to the other developer. It is difficult to send all the content one by one because it consumes too much time and effort. For that purpose, it is necessary to store all the content in a single archive file. Furthermore, the user can keep the backup of the project for later use by making an archive file.
This tutorial will elaborate:
What is the “git archive” Command in Git?
The “git archive” command permits the developers to package the entire history of a particular Git repository into a single archive file. This archive file includes all the branches, commits, and changes. The file must be in the form of a “tar” or “zip” archive. It is an effective procedure to share the Git repository with other developers or to make a backup of the codebase.
How to Use the “git archive” Command in Git?
To use the “git archive” command in Git, follow the below-stated steps:
- Move to the Git root directory.
- List all data using the “ls” command.
- Execute the “git archive” command for making an archive package.
- Verify the created package by listing content.
Step 1: Navigate to Git Root Directory
First of all, go to the Git root directory with the help of the “cd” command:
Step 2: List Available Data
To list all the existing content, execute the “ls” command:
Step 3: Make an Archive File
Now, execute the “git archive” command along with the parent branch name and specify the file name with the format:
Note: By default, the output will be produced in “tar” format, so it would be better to save it in a zip file, such as “gzip” or “b2zip” format.
Step 4: Verify the Archived File
Verify the existence of the archive file in the Git root directory by running the “ls” command:
It can be noticed that the archive file has been created and is available as the content of the Git root directory:
That’s all about using the “git archive” command in Git.
Conclusion
The “git archive” command permits the developers to make a package of the entire history of a particular Git repository into a single archive file. To use the “git archive” command in Git, first, redirect to the Git root directory and list all data using the “ls” command. Then, use the “git archive” command to make an archive package. Lastly, verify the created package by listing the content. This guide has stated about using the “git archive” command in Git.
Source: linuxhint.com