1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

gitでfetchとpushを別リポジトリに設定

Last updated at Posted at 2024-03-02

背景

外部ツールの更新をfetchしつつ、カスタマイズした内容を自分のリポジトリにpushしたかった(手軽に)

ローカルリポジトリを作成

任意のリポジトリを作成、またはclone

git clone https://github.com/hoge/fuga

もしshallow cloneしている場合は以下で全体を取得

git fetch --unshallow

リモートリポジトリを確認

git remote -v
>>> origin  https://github.com/hoge/fuga (fetch)
>>> origin  https://github.com/hoge/fuga (push)

この段階ではfetchとpushで同一のurlが設定されているため、push先を別urlに設定する

push先を別リポジトリに設定

git remote set-url --push origin https://github.com/piyo

リモートリポジトリを再度確認

git remote -v
>>> origin  https://github.com/hoge/fuga (fetch)
>>> origin  https://github.com/piyo (push)

これで簡単にfetchとpushができるようになった

git fetch
git push

番外(remoteコマンドのオプション)

git remote --helpで見られる

       git remote [-v | --verbose]
       git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=<fetch|push>] <name> <url>
       git remote rename <old> <new>
       git remote remove <name>
       git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
       git remote set-branches [--add] <name> <branch>...
       git remote get-url [--push] [--all] <name>
       git remote set-url [--push] <name> <newurl> [<oldurl>]
       git remote set-url --add [--push] <name> <newurl>
       git remote set-url --delete [--push] <name> <url>
       git remote [-v | --verbose] show [-n] <name>...
       git remote prune [-n | --dry-run] <name>...
       git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]

TODO

git remoteコマンドのオプションの詳細説明

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?