LoginSignup
5
6

More than 5 years have passed since last update.

Git入門(個人用)

Last updated at Posted at 2016-07-14

概要

gitの基本的なコマンドの使い方とGitHubなどを使用する際の手順などを説明する.

gitの基本コマンド

ここでは(個人的に)よく使うコマンドを記載する.
詳しいオプションなどは書かないこととしています.

コマンド 意味 使用例
git init リポジトリを初期化する git init
git status リポジトリの状態を確認する git status
git commit -m "コメント" リポジトリをコメントをつけてセーブする git commit -m "first commit"
git add --all リポジトリ内の変更されたファイルをステージに追加する git add --all
git branch 現在のブランチを確認する git branch
git branch [ブランチ名] ブランチ名に指定したブランチを作る git branch test
git checkout [ブランチ名] ブランチを移動する git checkout test
git push [リモートブランチ名] リモートリポジトリへの送信 git push origin master
git pull リモートのマスターブランチのデータを受信する git pull
git clone [リモートリポジトリ名] リモートリポジトリを取得する git clone https://github.com/makky0620/Test

gitの手順

ここでは以下の手順で説明する.
1. リモートリポジトリを取得する
2. ファイルを追加/変更し,送信の準備をする
3. リモートリポジトリへ送信する

リモートリポジトリを取得する

GitHub上からリポジトリのアドレス(URL)をコピーしておく

newrepo.PNG

そうしたら以下のコマンドで完了

user@username: git clone https://github.com/makky0620/Test.git

ファイルを追加/変更し,送信の準備をする

ここではブランチを切り,テキストファイルを追加し,リモートリポジトリへ送信できる状態にする.

まず初めに適当にブランチを作り,移動する

user@username: git branch test
user@username: git checkout test

作られたリポジトリ内に何らかのテキストファイスを作る(ここではtext.txtとする)

作成後以下のstatusコマンドを打ち,現在の状態を確認すると以下のようになっているはず.

user@username: git status
On branch test
Untracked files:
 (use "git add <file>..." to include in what will be committed)

   test.txt

nothing added to commit but untracked files present (use "git add" to track)

新しいファイルがありますが,送信できる状態じゃないですよっていうことです.なので以下のコマンドで送信できる状態にして,また状態を確認してみます.

user@username: git add --all
user@username: git status
On branch test
Changes to be committed
 (use "git reset HEAD <file>..." to unstage)

   new file: test.txt

これで送信できる状態になっています.

リモートリポジトリへ送信する

ここではリモートリポジトリへ送信をします.
今までの工程を終えて,最後にどのような変更を加えたのかを以下のコマンドを使用して書く

user@username: git commit -m "add test.txt"

そうしたら最後にリモートリポジトリへ以下のコマンドで送信する.

user@username: git push origin test

ここでGitHubのユーザ名とパスワードが聞かれるが,正しく打てば,送信ができる.
ちなみに最後のコマンドはGitHub上(リモート)にtestってブランチを作って,変更したデータを送信するよって意味です.
GitHubを見てみるとtestというブランチが追加されているはず.

5
6
2

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
5
6