LoginSignup
371

More than 5 years have passed since last update.

すぐ分かる! git の origin と master ってなんだ?

Last updated at Posted at 2013-08-02

前提知識

Gitは、分散レポジトリ
だから
「どのレポジトリ」の「どのブランチ」かを指定しないとわからないよ!

origin と master

  • origin: レポジトリの場所(URL)の別名
  • master: ブランチの名前

つまり、"git pull origin master" は、originという名前のレポジトリのマスターブランチから、git pull しろと命令している。

デフォルト

origin と master はデフォルトだよ。
つまり、 "git pull" = "git pull origin master"

別名はどこを指してるんだよ?

% git config --list

以下みたいにどこを指しているかわかる!

remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=https://github.com/ユーザ名/レポジトリ名.git

俺だって別名つけてーよ

GitHub のレポジトリに名前つけちゃおう。

git remote add 別名 https://github.com/ユーザ名/レポジトリ.git

git remote add upstream https://github.com/user/repositry.git

あちこちのレポジトリを追加して、あちこちに push すればいいさ。

別のレポジトリに push しちゃうぜ

GitHub から持ってきたソースを Bitbucket にpush しちゃおう。

Bitbucketのサイトでレポジトリを新規作成してから

git remote add bitbucket https://ユーザ名@bitbucket.org/ユーザ名/レポジトリ名.git

で、 git config --list

remote.bitbucket.url=https://ユーザ名@bitbucket.org/ユーザ名/レポジトリ名.git
remote.bitbucket.fetch=+refs/heads/:refs/remotes/gitbreak/

push する
git push はデフォルトでは、同じブランチ名がリモート上にある場合、全部のブランチを push しちゃう?

git push -b bitbucket master

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
371