はじめに
githubでリポジトリを新規に作りたいときのパターン例です。
新規で作る操作は比較的少ないと思うので、いまさらながら整理の意味もこめてどなたかの役に立てば、と。
ながれ
ながれというかこんなストーリー的なパターンでやります。
3に関しては1とあまり変わらないですね。
1. github上でリポジトリ作成 -> コマンドでgit initではじめる(githubのサンプルに従う)
このパターンのながれ
やってみる

- リポジトリ名を決めてcreate

- はじめるサンプルが表示されるのでそれに従って開始(git init)

ここから↑のサンプルに従ってコマンド
※ 適当なフォルダに移動
# cd ~/github
※ 作業用の場所をつくって移動する
# mkdir git-push-test
# cd git-push-test
※ -- ここからは従う --
※ 適当なファイルを作る
# touch sample.txt
※ git initする
# git init
Initialized empty Git repository in /Users/tweeeety/github/git-push-test/.git/
※ この時点で.gitディレクトリが作成される
# ls -al
drwxr-xr-x 10 tweeeety tweeeety 340 11 19 23:21 .git
※ configもこんなん
# cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
※ add, comitする
# git add sample.txt
# git commit -m 'first commit'
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 sample.txt
# git remote add origin git@github.com:tweeeety/git-push-test.git
※ この時点でconfigにremote "origin"についての情報が追加される
# cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = git@github.com:tweeeety/git-push-test.git
fetch = +refs/heads/*:refs/remotes/origin/*
# git push -u origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 225 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:tweeeety/git-push-test.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
という感じでめでたくリポジトリ作成からのfirst pushができました
2. github上でリポジトリ作成 -> コマンドでgit cloneではじめる
このパターンのながれ
やってみる
最初のふたつは上述と同じなのではぶきます。違いは3番目から。
createした後に表示される画面でサンプルではなく、リポジトリURLを使ってcloneします。

ということでコマンド
※ 適当なフォルダに移動 # cd ~/github ※ リポジトリURLを使ってclone ※ このパターンはディレクトリごと作成されるので↑と違ってmkdirしない。 # git clone git@github.com:tweeeety/git-push-test2.git Cloning into 'git-push-test2'... warning: You appear to have cloned an empty repository. Checking connectivity... done. # cd git-push-test2 # ls -al drwxr-xr-x 10 tweeeety tweeeety 340 11 19 23:31 .git ※ この時点でconfigには結構情報が追加されてる # cat .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true [remote "origin"] url = git@github.com:tweeeety/git-push-test2.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master ※ コレ以降はだいたい同じ # touch sample.txt # git add sample.txt # git commit -m 'first commit' # git push -u origin master
3. コマンドでgit init -> github上でリポジトリ作成 -> git push
このパターンのながれ
やってみる
自分はたまーにやっちゃいますが、github開くのがおっくうで先にinitしてしまうパターンです。 基本的には1と似てますね。
ということでコマンドから
※ 適当なフォルダに移動 # cd ~/github ※ 作業用の場所をつくって移動する # mkdir git-push-test3 # cd git-push-test3 # touch sample.txt ※ git initする # git init Initialized empty Git repository in /Users/tweeeety/github/git-push-test3/.git/ # git add sample.txt # git commit -m 'first commit' ※ git pushしてみる ※ 当然ながらどこに対してpushするかわからないので怒られる # git push -u origin master fatal: 'origin' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
ということでgithub上の+ New repositoryからリポジトリを作成します。
作り方は1と同じ。
作ったらpushしてみますが、pushの前にremoteを指定します
この時点でのconfigみてみる # pwd /Users/tweeeety/github/git-push-test3 # cat .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true # git remote add origin git@github.com:tweeeety/git-push-test3.git ※ remote情報が追加された # cat .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true [remote "origin"] url = git@github.com:tweeeety/git-push-test3.git fetch = +refs/heads/*:refs/remotes/origin/* # git push -u origin master Counting objects: 3, done. Writing objects: 100% (3/3), 225 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@github.com:tweeeety/git-push-test3.git * [new branch] master -> master Branch master set up to track remote branch master from origin.
無事pushできました。
まとめ
いまとなってはあたりまえなことだけど整理するのも大事って思う、ってことで。