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 3 years have passed since last update.

GitHub memo

Last updated at Posted at 2021-01-31

自分のローカルのマシンにディレクトリを作り、

GitHubでTestProjectというレポジトリを作ると、複数のヒントが表示される。

(1) ... or create a new repository on the command line

echo "# TestProject" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/[ ... ]/TestProject.git
git push -u origin main

(2) ... or push an existing repository from the command line

git remote add origin https://github.com/[ ... ]/TestProject.git
git branch -M main
git push -u origin main

これらを順番にテストしてみる。

(1) ローカルでフォルダを作り、そこからGitHubに送る。

$ cd GitHub 
$ mkdir TestProject
$ cd TestProject/

$ echo "# TestProject" >> README.md

$ git init
Initialized empty Git repository in /Users/kohei/Documents/GitHub/TestProject/.git/

$ git add README.md

$ git commit -m "first commit"
[master (root-commit) 5155190] first commit
 Committer: 
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+)
 create mode 100644 README.md

$ git branch -M main

$ git remote add origin https://github.com/[ .... ]/TestProject.git

$ git push -u origin main

Counting objects: 3, done.
Writing objects: 100% (3/3), 227 bytes | 227.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/[ .... ]/TestProject.git
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.

さらに、新しいファイルをpushする

$ ls -l
README.md
sample_code.py # これが新しいファイル

$ git add .

$ git commit -m "Add existing file"

$ git push origin main

既存のプロジェクウトのブランチを作る。

その上で、ローカルのディレクトリにおいて以下のようにする。

# ブランチを作成する。
$ git branch feature-branch1

# 現在自分がいるブランチがどれなのかを表示する
$ git branch
  feature-branch1
* main

# 新しいブランチに移動する。
$ git checkout feature-branch1
Switched to branch 'feature-branch1'

# 新しいブランチに移動していることを確認する。
$ git branch
* feature-branch1
  main

# 何か新しいファイルを作ってみる。
$ echo "# Add a file for new branch." >> test.txt
$ ls -l
README.md
sample_code.py
test.txt # 新しいファイル

$ git add --all

$ git commit -m "push to a new branch named feature-branch1."
[feature-branch1 3580623] push to a new branch named feature-branch1.

 1 file changed, 1 insertion(+)
 create mode 100644 test.txt

$ git push origin feature-branch1

Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 372 bytes | 372.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/[ ... ]/TestProject.git
   41cd612..3580623  feature-branch1 -> feature-branch1

GiyHubのレポジトリのページで、"Find or create a branch..."のところに新しいブランチ名 feature-branch1 を入れてEnterを押すことで、新しいブランチを作ることもできる。

github_fig1.png

参考: https://qiita.com/ryuji_i3/items/7dafb4cc00726d8ee0c3 

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?