Files
rsmsn_blog/public/posts/multiple_git_remotes.html

306 lines
18 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en" dir="auto">
<head><meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="robots" content="index, follow">
<title>Pushing a Single Local Git Repo to Multiple Remote Repos | Norm-working Packets 💾</title>
<meta name="keywords" content="git, backups, commandline">
<meta name="description" content="Learn one way to push your git changes to multiple remote repositories.">
<meta name="author" content="Me">
<link rel="canonical" href="../posts/multiple_git_remotes.html">
<link crossorigin="anonymous" href="../assets/css/stylesheet.5cfc680b1eeaeef9efbced92d46c2a9e876b72ee14fba85846afc4cff9e6e6f8.css" integrity="sha256-XPxoCx7q7vnvvO2S1Gwqnodrcu4U&#43;6hYRq/Ez/nm5vg=" rel="preload stylesheet" as="style">
<script defer crossorigin="anonymous" src="../assets/js/highlight.f413e19d0714851f6474e7ee9632408e58ac146fbdbe62747134bea2fa3415e0.js" integrity="sha256-9BPhnQcUhR9kdOfuljJAjlisFG&#43;9vmJ0cTS&#43;ovo0FeA="
onload="hljs.initHighlightingOnLoad();"></script>
<link rel="icon" href="../favicon.ico">
<link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../rsmsncircles.ico">
<link rel="apple-touch-icon" href="../apple-touch-icon.png">
<link rel="mask-icon" href="../safari-pinned-tab.svg">
<meta name="theme-color" content="#2e2e33">
<meta name="msapplication-TileColor" content="#2e2e33">
<noscript>
<style>
#theme-toggle,
.top-link {
display: none;
}
</style>
</noscript>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-X8VR5M0K20"></script>
<script>
var doNotTrack = false;
if (!doNotTrack) {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-X8VR5M0K20', { 'anonymize_ip': false });
}
</script>
<meta property="og:title" content="Pushing a Single Local Git Repo to Multiple Remote Repos" />
<meta property="og:description" content="Learn one way to push your git changes to multiple remote repositories." />
<meta property="og:type" content="article" />
<meta property="og:url" content="/posts/multiple_git_remotes.html" />
<meta property="og:image" content="/multiple-git-cover-img.png" /><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2023-09-22T15:07:10-04:00" />
<meta property="article:modified_time" content="2023-09-22T15:07:10-04:00" /><meta property="og:site_name" content="Norm-working Packets" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:image" content="/multiple-git-cover-img.png" />
<meta name="twitter:title" content="Pushing a Single Local Git Repo to Multiple Remote Repos"/>
<meta name="twitter:description" content="Learn one way to push your git changes to multiple remote repositories."/>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1 ,
"name": "Pushing a Single Local Git Repo to Multiple Remote Repos",
"item": "/posts/multiple_git_remotes.html"
}
]
}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BlogPosting",
"headline": "Pushing a Single Local Git Repo to Multiple Remote Repos",
"name": "Pushing a Single Local Git Repo to Multiple Remote Repos",
"description": "Learn one way to push your git changes to multiple remote repositories.",
"keywords": [
"git", "backups", "commandline"
],
"articleBody": "Why push to multiple repos? Do want to use both Github \u0026 and a Self-hosted Git Repo? Heres how Ive been doing it!\nI really enjoy self-hosting services that I use everyday. One of those includes a git-style version control software. In my case, Ive been running Gitea for a few years now and have been really satisfied with everything (except for that one time that an update broke all my templates).\nAt the same time, theres the entire social element that comes with Github along with having your public repositories available in a place that other developers are already spending time on. Instead of adding, committing, commenting, and pushing on two different repos, heres how I run all those commands just once and push it to both repos.\nNote: An import git note to remember is that you can only push to multiple remote repositories. Youll have to select which repo you want to be the main pull repository. Have this be remote-url-one in the below instructions.\nCommand Line Instructions These instructions come after you initialize the repo in your directory. Make sure you have both of your remote git URLs handy at this point!\ngit remote add {{ remote-name }} {{ remote-url-one }} git remote set-url --add --push {{ remote-name }} {{ remote-url-one }} git remote set-url --add --push {{ remote-name }} {{ remote-url-two }} To confirm that everything worked as expected, run git remote -v to check your remote repos. You should see one repo in there twice, once for (push) and once for (fetch).\nI use the remote name “all” for multiple repos, so heres what my git remote -v returns:\n\u003e git remote -v all https://git.rsmsn.co/Normanras/rsmsn_blog.git (fetch) all https://git.rsmsn.co/Normanras/rsmsn_blog.git (push) all https://github.com/Normanras/rsmsn_blog.git (push) all https://git.rsmsn.co/Normanras/rsmsn_ddblog.git (push) To now push to your repositories, after adding and committing run git push {{ remote-name }} --all. My command is git push all --all (see why I use all, now?)\nHeres the man page description on the --all flag:\n--all Push all branches (i.e. refs under refs/heads/); cannot be used Instead of naming each ref to push, specifies that all refs under end, locally updated refs will be force updated on the remote end, Do everything except actually send the updates. same as prefixing all refs with a colon. And thats it! You should be able to push everything to both of your repos fairly easily now with this new set commands.\n",
"wordCount" : "403",
"inLanguage": "en",
"image":"/multiple-git-cover-img.png","datePublished": "2023-09-22T15:07:10-04:00",
"dateModified": "2023-09-22T15:07:10-04:00",
"author":{
"@type": "Person",
"name": "Me"
},
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "/posts/multiple_git_remotes.html"
},
"publisher": {
"@type": "Organization",
"name": "Norm-working Packets 💾",
"logo": {
"@type": "ImageObject",
"url": "/favicon.ico"
}
}
}
</script>
</head>
<body class=" dark" id="top">
<script>
if (localStorage.getItem("pref-theme") === "light") {
document.body.classList.remove('dark')
}
</script>
<header class="header">
<nav class="nav">
<div class="logo">
<a href="../" accesskey="h" title="Norm-working Packets 💾 (Alt + H)">Norm-working Packets 💾</a>
<div class="logo-switches">
<button id="theme-toggle" accesskey="t" title="(Alt + T)">
<svg id="moon" xmlns="http://www.w3.org/2000/svg" width="24" height="18" viewBox="0 0 24 24"
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round">
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path>
</svg>
<svg id="sun" xmlns="http://www.w3.org/2000/svg" width="24" height="18" viewBox="0 0 24 24"
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round">
<circle cx="12" cy="12" r="5"></circle>
<line x1="12" y1="1" x2="12" y2="3"></line>
<line x1="12" y1="21" x2="12" y2="23"></line>
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
<line x1="1" y1="12" x2="3" y2="12"></line>
<line x1="21" y1="12" x2="23" y2="12"></line>
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
</svg>
</button>
</div>
</div>
<ul id="menu">
</ul>
</nav>
</header>
<main class="main">
<article class="post-single">
<header class="post-header">
<div class="breadcrumbs"><a href="../">Home</a></div>
<h1 class="post-title">
Pushing a Single Local Git Repo to Multiple Remote Repos
</h1>
<div class="post-description">
Learn one way to push your git changes to multiple remote repositories.
</div>
<div class="post-meta"><span title='2023-09-22 15:07:10 -0400 EDT'>September 22, 2023</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;403 words&nbsp;·&nbsp;Me
</div>
</header> <div class="toc">
<details >
<summary accesskey="c" title="(Alt + C)">
<span class="details">Table of Contents</span>
</summary>
<div class="inner"><nav id="TableOfContents">
<ul>
<li><a href="#why-push-to-multiple-repos">Why push to multiple repos?</a></li>
<li><a href="#command-line-instructions">Command Line Instructions</a></li>
</ul>
</nav>
</div>
</details>
</div>
<div class="post-content"><h2 id="why-push-to-multiple-repos">Why push to multiple repos?<a hidden class="anchor" aria-hidden="true" href="#why-push-to-multiple-repos">#</a></h2>
<p>Do want to use both Github &amp; and a Self-hosted Git Repo? Here&rsquo;s how I&rsquo;ve been doing it!</p>
<p>I really enjoy self-hosting services that I use everyday. One of those includes a git-style version control software. In my
case, I&rsquo;ve been running <a href="https://gitea.com/">Gitea</a> for a few years now and have been really satisfied with everything (except
for that one time that an update broke all my templates).</p>
<p>At the same time, there&rsquo;s the entire social element that comes with Github along with having your public repositories
available in a place that other developers are already spending time on. Instead of adding, committing, commenting, and
pushing on two different repos, here&rsquo;s how I run all those commands just once and push it to both repos.</p>
<p><em>Note: An import git note to remember is that you can only <em>push</em> to multiple remote repositories. You&rsquo;ll have to select
which repo you want to be the main pull repository. Have this be <code>remote-url-one</code> in the below instructions.</em></p>
<h2 id="command-line-instructions">Command Line Instructions<a hidden class="anchor" aria-hidden="true" href="#command-line-instructions">#</a></h2>
<p>These instructions come after you initialize the repo in your directory. Make sure you have both of your remote git URLs
handy at this point!</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-zsh" data-lang="zsh"><span style="display:flex;"><span>git remote add <span style="color:#f92672">{{</span> remote-name <span style="color:#f92672">}}</span> <span style="color:#f92672">{{</span> remote-url-one <span style="color:#f92672">}}</span>
</span></span><span style="display:flex;"><span>git remote set-url --add --push <span style="color:#f92672">{{</span> remote-name <span style="color:#f92672">}}</span> <span style="color:#f92672">{{</span> remote-url-one <span style="color:#f92672">}}</span>
</span></span><span style="display:flex;"><span>git remote set-url --add --push <span style="color:#f92672">{{</span> remote-name <span style="color:#f92672">}}</span> <span style="color:#f92672">{{</span> remote-url-two <span style="color:#f92672">}}</span>
</span></span></code></pre></div><p>To confirm that everything worked as expected, run <code>git remote -v</code> to check your remote repos. You should see one repo in
there twice, once for <code>(push)</code> and once for <code>(fetch)</code>.</p>
<p>I use the remote name &ldquo;all&rdquo; for multiple repos, so here&rsquo;s what my <code>git remote -v</code> returns:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-zsh" data-lang="zsh"><span style="display:flex;"><span>&gt; git remote -v
</span></span><span style="display:flex;"><span>all https://git.rsmsn.co/Normanras/rsmsn_blog.git <span style="color:#f92672">(</span>fetch<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>all https://git.rsmsn.co/Normanras/rsmsn_blog.git <span style="color:#f92672">(</span>push<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>all https://github.com/Normanras/rsmsn_blog.git <span style="color:#f92672">(</span>push<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>all https://git.rsmsn.co/Normanras/rsmsn_ddblog.git <span style="color:#f92672">(</span>push<span style="color:#f92672">)</span>
</span></span></code></pre></div><p>To now push to your repositories, after adding and committing run <code>git push {{ remote-name }} --all</code>. My command is
<code>git push all --all</code> (see why I use all, now?)</p>
<p>Here&rsquo;s the man page description on the <code>--all</code> flag:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-zsh" data-lang="zsh"><span style="display:flex;"><span>--all
</span></span><span style="display:flex;"><span> Push all branches <span style="color:#f92672">(</span>i.e. refs under refs/heads/<span style="color:#f92672">)</span>; cannot be used
</span></span><span style="display:flex;"><span> Instead of naming each ref to push, specifies that all refs under
</span></span><span style="display:flex;"><span> end, locally updated refs will be force updated on the remote end,
</span></span><span style="display:flex;"><span> Do everything except actually send the updates.
</span></span><span style="display:flex;"><span> same as prefixing all refs with a colon.
</span></span></code></pre></div><p>And that&rsquo;s it! You should be able to push everything to both of your repos fairly easily now with this new set commands.</p>
</div>
<footer class="post-footer">
<ul class="post-tags">
<li><a href="../tags/git.html">git</a></li>
<li><a href="../tags/backups.html">backups</a></li>
<li><a href="../tags/commandline.html">commandline</a></li>
</ul>
<nav class="paginav">
<a class="prev" href="../posts/new-favorite-website.html">
<span class="title">« Prev</span>
<br>
<span>New Favorite Website!</span>
</a>
<a class="next" href="../posts/hosting_hugo_troubles.html">
<span class="title">Next »</span>
<br>
<span>Trouble Hosting Hugo with Nginx</span>
</a>
</nav>
</footer>
</article>
</main>
<footer class="footer">
<span>&copy; 2023 <a href="../">Norm-working Packets 💾</a></span>
<span>
Powered by
<a href="https://gohugo.io/" rel="noopener noreferrer" target="_blank">Hugo</a> &
<a href="https://github.com/adityatelange/hugo-PaperMod/" rel="noopener" target="_blank">PaperMod</a>
</span>
</footer>
<a href="#top" aria-label="go to top" title="Go to Top (Alt + G)" class="top-link" id="top-link" accesskey="g">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 6" fill="currentColor">
<path d="M12 6H0l6-6z" />
</svg>
</a>
<script>
let menu = document.getElementById('menu')
if (menu) {
menu.scrollLeft = localStorage.getItem("menu-scroll-position");
menu.onscroll = function () {
localStorage.setItem("menu-scroll-position", menu.scrollLeft);
}
}
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener("click", function (e) {
e.preventDefault();
var id = this.getAttribute("href").substr(1);
if (!window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView({
behavior: "smooth"
});
} else {
document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView();
}
if (id === "top") {
history.replaceState(null, null, " ");
} else {
history.pushState(null, null, `#${id}`);
}
});
});
</script>
<script>
var mybutton = document.getElementById("top-link");
window.onscroll = function () {
if (document.body.scrollTop > 800 || document.documentElement.scrollTop > 800) {
mybutton.style.visibility = "visible";
mybutton.style.opacity = "1";
} else {
mybutton.style.visibility = "hidden";
mybutton.style.opacity = "0";
}
};
</script>
<script>
document.getElementById("theme-toggle").addEventListener("click", () => {
if (document.body.className.includes("dark")) {
document.body.classList.remove('dark');
localStorage.setItem("pref-theme", 'light');
} else {
document.body.classList.add('dark');
localStorage.setItem("pref-theme", 'dark');
}
})
</script>
</body>
</html>