LoginSignup
51
50

More than 5 years have passed since last update.

Git初心者に役立つ「よく使うコマンド集」②

Posted at

Git初心者に役立つ「よく使うコマンド集」
の続きで書こうと思います。

リモートリポジトリを追加する

git remote add [reponame] [url]

このように、リモートリポジトリに名前([reponame])をつけることができます。
ちなみにクローンしたリポジトリの名前はデフォルトで origin という名前がついています。

リモートリポジトリの一覧を表示する

git remote

自分で設定した名前が表示されます。

ex
git remote

origin
other

urlをみたいときは-vを付けます。

ex
git remote -v

origin git://github.com/*****/*****.git (fetch)
origin git://github.com/*****/*****.git (push)
other git://github.com/*****/*****.git (fetch)
other git://github.com/*****/*****.git (push)

fetchする

git fetch [reponame]

ローカルにブランチを作成する

git checkout -b [branchname] [(reponame/) branch]

branchnameを指定して、ローカルにブランチを作成します。
-bを付けることでブランチを作成した後、自動的にcheckoutします。
リモートリポジトリが一つ(origin)のみの場合はreponame/がなくても実行できます。

pushする

git push [reponame] [branchname]:[branch]

reponameリポジトリのbranchに、ローカルブランチのbranchnameをプッシュします。
しばしば以下のように省略されます。

ex
git push origin develop

省略して書かないと以下のようになります。

ex
git push origin develop:develop

ローカルブランチとリモートブランチが同じ名前の場合は省略して書くことができます。

pullする

git pull [reponame] [branch]

ブランチを削除する

git branch -d [branchname]

リモートリポジトリを削除する

git remote rm [reponame]

ブランチの一覧を見る

git branch -a

-aをつけることでローカルブランチだけではなく、リモートブランチの一覧も一緒に表示することができます。

51
50
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
51
50