Now we’re ready to send those updated references back to the origin repository: $ git push -prune +refs/remotes/origin/*:refs/heads/* +refs/tags/*:refs/tags/* Finally, mirroring the repository to a new location This will update your references to the origin repository and also clean the stale branches reported by git branch -r. We need to clean those old references before mirroring them to a new location. Why? Cleaning old references to remote branchesīy default, when you do a git fetch or git pull, git will not delete the references to branches that were deleted in the upstream repository (you may view them in your. If you pay attention to that list, tough, you may notice that you have a lot of branches that were already deleted in the upstream repository. But you do have references to remote branches. In this case, you may have a lot of local branches and tags that you don’t want to copy to the new location. Mirroring a git repository if you already have a local working copyīy working copy, we mean a “normal” repository, in which you have the files that are being tracked into git and where you perform commands like git add and so on. Read the next section to discover what to do in these cases.Īlso git clone -mirror is prefered over git clone -bare because the former also clones git notes and some other attributes. It’ll overwrite the remote repository with your local references (and your local branches). Warningĭon’t use git push -mirror in repositories that weren’t cloned by -mirror as well. $ git push -mirror will get all the branches and tags that are available in the upstream repository and will replicate those into the new location. If you haven’t cloned the repository before, you can mirror it to a new home by $ git clone -mirror cd upstream-repository.git Mirroring a git repository without a local copy The difference lays on whether you already have a working copy of that repository or not. You’ll need to do this when migrating your upstream repository to a new “home”, like when switching services like GitHub.Īs with most tools, there’s a lot of ways to accomplish that, but I’ll be focusing on two of them. By state, we mean all the branches (including master) and all the tags as well. However, what we want with mirroring is to replicate the state of an origin repository (or upstream repository). When people talk about mirroring a git repository, usually we have a simple answer in mind: How to properly mirror a git repository May 21, 2013
0 Comments
Leave a Reply. |