Skip to content

Conversation

@ravimahey
Copy link
Owner

@ravimahey ravimahey commented Jan 24, 2025

Git Push with Mirroring

This document describes how to use Git to push all branches, tags, and references to a remote repository with mirroring functionality.

Example Command

git push --mirror origin

Explanation of Flags

Flag Description
--mirror Ensures that all refs (branches, tags, and other references) are pushed and synchronized exactly.
origin The name of the remote repository to which you are pushing.

HTML Table Example

Below is an example of an HTML table that displays the same information:

<table>
  <thead>
    <tr>
      <th>Flag</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>--mirror</td>
      <td>Ensures that all refs (branches, tags, and other references) are pushed and synchronized exactly.</td>
    </tr>
    <tr>
      <td>origin</td>
      <td>The name of the remote repository to which you are pushing.</td>
    </tr>
  </tbody>
</table>

Node.js Example with simple-git

If you are using Node.js to programmatically push with mirroring, here is an example:

const simpleGit = require('simple-git');

const git = simpleGit();

(async () => {
  try {
    // Push all branches and tags to the origin
    await git.push('origin', '--mirror');
    console.log('Mirroring to origin successful!');
  } catch (err) {
    console.error('Error while mirroring:', err);
  }
})();

Use Cases

  • Backing up a repository to another remote.
  • Synchronizing repositories across multiple locations.
  • Migrating repositories while maintaining full history and refs.

@ravimahey
Copy link
Owner Author

comment1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants