Change to a profile style page, added post about multiple git repos. Need to write script to auto-update blog posts.
This commit is contained in:
83
content/posts/multiple_git_remotes.md
Normal file
83
content/posts/multiple_git_remotes.md
Normal file
@ -0,0 +1,83 @@
|
||||
---
|
||||
title: 'Pushing a Single Local Git Repo to Multiple Remote Repos'
|
||||
date: 2023-09-22T15:07:10-04:00
|
||||
tags: ["git", "backups", "commandline"]
|
||||
author: "Me"
|
||||
showToc: true
|
||||
TocOpen: false
|
||||
draft: false
|
||||
hidemeta: false
|
||||
description: "Learn one way to push your git changes to multiple remote repositories."
|
||||
disableHLJS: false # to disable highlightjs
|
||||
disableShare: false
|
||||
disableHLJS: false
|
||||
hideSummary: false
|
||||
searchHidden: true
|
||||
ShowReadingTime: true
|
||||
ShowBreadCrumbs: true
|
||||
ShowPostNavLinks: true
|
||||
ShowWordCount: true
|
||||
ShowRssButtonInSectionTermList: true
|
||||
UseHugoToc: true
|
||||
cover:
|
||||
image: "<image path/url>" # image path/url
|
||||
alt: "<alt text>" # alt text
|
||||
caption: "<text>" # display caption under cover
|
||||
relative: false # when using page bundles set this to true
|
||||
hidden: true # only hide on current single page
|
||||
---
|
||||
|
||||
## Why push to multiple repos?
|
||||
|
||||
Do want to use both Github & and a Self-hosted Git Repo? Here's how I've been doing it!
|
||||
|
||||
I really enjoy self-hosting services that I use everyday. One of those includes a git-style version control software. In my
|
||||
case, I've been running [Gitea](https://gitea.com/) for a few years now and have been really satisfied with everything (except
|
||||
for that one time that an update broke all my templates).
|
||||
|
||||
At the same time, there'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's how I run all those commands just once and push it to both repos.
|
||||
|
||||
_Note: An import git note to remember is that you can only _push_ to multiple remote repositories. You'll have to select
|
||||
which repo you want to be the main pull repository. Have this be `remote-url-one` in the below instructions._
|
||||
|
||||
## Command 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!
|
||||
|
||||
```zsh
|
||||
git 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)`.
|
||||
|
||||
I use the remote name "all" for multiple repos, so here's what my `git remote -v` returns:
|
||||
|
||||
```zsh
|
||||
> 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?)
|
||||
|
||||
Here's the man page description on the `--all` flag:
|
||||
|
||||
```zsh
|
||||
--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 that's it! You should be able to push everything to both of your repos fairly easily now with this new set commands.
|
||||
Reference in New Issue
Block a user