0
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?

More than 5 years have passed since last update.

Git使い方メモ

Posted at

はじめに

gitとGitHubを勉強して、自分なりに実際に使用してみたので、その流れをメモしておきたいと思います。

git管理の開始

GitHubの操作

リポジトリ作成
まず、GitHub上でリモートリポジトリを作成します。
GitHubのRepositories欄の「New」ボタンから作成できます。
new repository1.png
リポジトリ名を入れれば作成できます。
new repository2.png

git操作

既にあるファイルの管理を始める場合は、管理するファイルがあるディレクトリに移動後に、git initコマンドを実行します。

git init

次に、git remoteコマンドでリモートリポジトリを登録します。
以下のコマンドによって、originというの名前でリモートリポジトリにアクセスできます。

git remote origin "アドレス"

以下のコマンドで現在登録しているリモートリポジトリを確認できます。

git remote -v

ブランチの操作

git branchコマンドでブランチを作成できます。

git branch "ブランチ名"

以下のコマンドで、ブランチの一覧を確認できます。
-aオプションをつけることで、リモートブランチを含めて確認できます。
また、*がついているものが現在のブランチになります。

git branch
git branch -a

作成したブランチに移動するには、git checkoutコマンドを使用します。
-bオプションをつけることで、ブランチの作成しつつ移動できます。

git checkout "ブランチ名"
git checkout -b "ブランチ名"

不要なリポジトリは、git branch -dで削除できます。

git branch -d "ブランチ名"

リモートブランチの場合は、git push --deleteコマンドになります。

git push --delete origin "ブランチ名"

ファイルの管理

ここからはファイル修正後の話です。

修正したファイルをインデックスに登録します。
簡単に言うと、コミットするファイル一覧みたいなものです。
git addコマンドで登録します。

git add "ファイル名"

git statusで現在の変更を確認できます。

git status

次にファイルをローカルリポジトリにコミットします。
デフォルトだとvimでコメント入力が起動するので、iで入力モード、
入力後は、escで入力モード終了、:wqで保存して終了します。

git commit

最後に、リモートリポジトリにプッシュして反映します。

git push origin "ブランチ名"

プルリクエスト

リモートリポジトリにプッシュされた内容を別のブランチにマージする際に、プルリクエストを送ります。
GitHubのPull requests欄の「New pull request」を押します。
pullrequest1.png
マージ元とマージ先のブランチを指定して、「Create pull request」を押して、必要項目を入力すると作成できます。
pullrequest2.png

GitHubの内容を取得

まず、取得したいブランチに移動します。

git checkout "ブランチ名"

git pullコマンドでリモートリポジトリの内容をローカルに反映します。

git pull origin "ブランチ名"

参考URL

以下の方の記事にコマンドがまとまっていて参考にしました。
【Git】基本コマンド
基本的なGitコマンドまとめ

0
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
0
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?