LoginSignup
2
2

More than 3 years have passed since last update.

GitHubでソース管理をする流れ

Last updated at Posted at 2020-03-22

環境
git version 2.25.1.windows.1

手順

1.リモートリポジトリをローカルに落とす

$ git clone git@github.com:【ユーザー名】/【リポジトリ名】.git

落としたリポジトリの確認

$ git branch
* master

作成された段階のリポジトリには「master」ブランチのみが存在します。

2.作業ブランチを作成する
修正をする場合、masterをコピーしたブランチを触る。

$ git branch copy_branch

ブランチ一覧を確認すると、コピーしたブランチができている。

$ git branch
* master
copy_branch

3.ブランチの移動
アスタリスクがついているのが現在選択中のブランチ。
作業ブランチに移動する。

$ git checkout copy_branch
Switched to branch 'copy_branch'

ブランチ一覧を確認すると、copy_branchにアスタリスクがついているのが確認できる。

$ git branch
master
* copy_branch    

4.ファイルを作成する
今回は単なるテキストファイルを作成します。

$ vi a.txt  

5.作成したファイルをバージョン管理の対象に追加する

コミットする前には必ずaddしなければなりません。
addすることでGitのコミット対象になります。

$ git add a.txt  

6.コミットする内容を確認する

$ git status
On branch copy_branch
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file:   a.txt

a.txtが追加されていることが確認できます。

7.コミットする

きちんとaddされている状態でコミットします。

$ git commit -m "test commit"
[xxx e6b74e6] test commit
1 files changed, 1 insertion(+)
create mode 100644 a.txt

コミットコメントはダブルクオートで囲んで記入します。

コミットが完了すると、statusは以下のようになります。

$ git status
On branch copy_branch
nothing to commit, working tree clean

8.GitHubへプッシュする
ローカル環境でコミットが完了したので、次にGitHubへ反映させます。

$ git push origin copy_branch
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 300 bytes | 150.00 KiB/s, done.
remote:
remote: Create a pull request for 'test' on GitHub by visiting:
remote:      https://github.com/user/test/pull/new/test
remote:
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/user/test.git
   e6b74e6..dd1235a  copy_branch -> copy_branch

9.プルリクを送る
先ほどpushしたときに出たhttps://github.com/user/test/pull/new/test へアクセスすると、プルリクを送れる画面に行けるのでコメント残してぽちります。

10.ローカルブランチを削除する

作業ブランチを違うブランチに切り替えてから削除を行います。

$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

$ git branch --d copy_branch
Deleted branch copy_branch (was dd1235a).

作業ブランチを変えないまま削除しようとすると、下記のようなエラーになります。

$ git branch --d copy_branch
error: Cannot delete branch 'copy_branch' checked out at 'C:/Users/test'

11.リモートリポジトリの最新を取得する
常に最新のmasterを取得し、それをコピーしたbranchで作業を行います。

$ git pull origin master
remote: Enumerating objects: 1, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (1/1), 621 bytes | 20.00 KiB/s, done.
From https://github.com/user/test
 * branch            master     -> FETCH_HEAD
   f8999d2..8d6e7ad  master     -> origin/master
Updating f8999d2..8d6e7ad
Fast-forward
 a.txt | 1 +
 b.txt | 0
 2 files changed, 1 insertion(+)
 create mode 100644 b.txt
2
2
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
2
2