LoginSignup
0
3

More than 3 years have passed since last update.

【超入門】GitHubでブランチを切る

Posted at

こんにちは、むんです:grinning:
今度GitHubを使うことになったのですが、しばらくSVNですっかり忘れてしまい。。
復習がてら、まとめました。

やること

GitHub上のリポジトリにブランチを切る。
(今回マージはしない)

目次

①developをクローン
②ブランチを切る
③ソースを改修
④ローカルリポジトリにadd
⑤ローカルリポジトリにcommit
⑥リモートリポジトリにpush

流れとしてはこんな感じ。
それでは詳しく説明していきます。

①developをクローンしてくる

$git clone {url} 
$cd {cloneで出来たディレクトリ名}

②ブランチを切る

まず、現在のブランチの状態を確認。

$git branch
$*develop

developが出来ているのを確認。
ブランチを切リましょう。

$git branch {ブランチ名}

ブランチが切られているか、確認。

$git branch
$*develop
${作成されたブランチ名}

ブランチが作成されている。
ブランチに移動。

$git checkout {ブランチ名}

ブランチに移動出来ているか、確認する。

$git branch
$develop
$*{作成されたブランチ名}

ブランチに移動出来ている。

③ソースを改修する

cloneしてきたフォルダ配下で改修する。

④ローカルリポジトリにコミットするファイルをadd

$git add {コミットするファイル名}

ステータスを確認する。

$git status
On branch {ブランチ名}
Changes to be committed:
 (use "git restore --staged <file>..." to unstage)
    new file:   src/index.html
    new file:   src/img/header.jpeg
    new file:   src/img/sub1.jpeg
    new file:   src/img/sub2.jpeg
    new file:   src/img/sub3.jpeg

意図した通り(今回は新規で追加したファイルが)出力される。

⑤ローカルリポジトリにファイルをcommit

$git commit -m "{コミット時のメッセージ}"

ログを確認する。

$git log
commit 40fd69c7634357748e31b817c91d12cbf1143f64 (HEAD -> {ブランチ名})
Author: Mun Hogehoge <mun.hogehoge@company.co.jp>
Date:   Sun Nov 22 11:01:34 2020 +0900

    Docker入門の記事を書きました //コミット時のメッセージ

⑥リモートリポジトリにpush

$git push origin {branch名}
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 431 bytes | 215.00 KiB/s, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/sample/sample.git
   1abcde2..123456f  {ブランチ名} -> src

GitHubを確認してみる。
意図した通りブランチが追加されているはず。
ブランチが追加出来ていなければ、何か手順に漏れがないか確認する。

まとめ

以上、リポジトリにブランチを切る手順でした。
次回はマージする手順を書きたいと思います。

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