ローカル間でリモートとのやり取りを行う

はじめに

こんなイメージのことをやっていく

http://localhost:8080

これがリモートリポジトリ

eki-api

eki-api/test/eki-api

testディレクトリ作成

gitignoreに加えてある

testディレクトリを開く

control + shift + ^ でターミナルを開く

git init

Mac:test shibatahiroshitaka$ git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint:   git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint:   git branch -m <name>
Initialized empty Git repository in /Users/shibatahiroshitaka/Downloads/python/eki-api/test/.git/

リモートURLを確認

git remote add origin http://localhost:8080/git/root/eki-api.git

クローンする

git clone http://localhost:8080/git/root/eki-api.git

Mac:test shibatahiroshitaka$ git clone http://localhost:8080/git/root/eki-api.git
Cloning into 'eki-api'...
remote: Counting objects: 11, done
remote: Finding sources: 100% (11/11)
remote: Getting sizes: 100% (7/7)
Receiving objects: 100% (11/11), 1.65 KiB | 282.00 KiB/s, done.
Resolving deltas: 100% (1/1), done.
remote: Total 11 (delta 1), reused 11 (delta 1)

クローンしたeki-apiを開く

(3.6.5) Mac:eki-api shibatahiroshitaka$ pwd
/Users/shibatahiroshitaka/Downloads/python/eki-api/test/eki-api

テスト用に変更を加える

control + shift + ` (なぜかコマンドが変わっていた。command + J でターミナルを閉じたからかもしれない)で、ターミナルを開く。

変更点をプッシュする

git add . → git commit →git push

(3.6.5) Mac:eki-api shibatahiroshitaka$ git add .
(3.6.5) Mac:eki-api shibatahiroshitaka$ git commit -m "テスト"
[master 18b97af] テスト
 1 file changed, 2 insertions(+), 1 deletion(-)
(3.6.5) Mac:eki-api shibatahiroshitaka$ git push origin master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 359 bytes | 359.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1)
remote: Updating references: 100% (1/1)
To http://localhost:8080/git/root/eki-api.git
   979cba7..18b97af  master -> master

push前

push後

eki-apiでプル

eki-apiを開く

eki-apiが最新化できる状態

変更点をプルする

git pull origin master

リモートの変更点が反映された。

こんな感じで、複数のローカルリポジトリと、一つのリモートリポジトリで、変更点の共有ができる。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です