facebook twitter hatena line email

Git/github/基本

提供: 初心者エンジニアの簡易メモ
2021年8月16日 (月) 23:40時点におけるAdmin (トーク | 投稿記録)による版

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索

セットアップ

  1. git/windowsインストール [ショートカット]
  2. githubのアカウントを作成
  3. ssh public keysでkeyにid_ssh.pubのテキストデータを入れる(タイトルは適当に
  4. Git Bashで以下コマンドを実行しconnection~成功と出ればOK
$ ssh git@github.com
  1. ユーザ名、メアド設定
$ git config --global user.name "自分のユーザー名"
$ git config --global user.email "自分のメアド"

リポジトリ作成

  1. 右中の[New repository]ボタンをクリック

自分のレポジトリについて他人に権限を与える

  1. repositoryのsettings/collaborationでusernameを追加する
  2. username側にinvitedメールが行くのでリンクをクリックしてもらう。

初回コミット方法

mkdir hellogithub
cd hellogithub
git init
touch hello.txt
git add hello.txt
git commit -m 'first commit'
git remote add origin git@github.com:[user1]/[project1]
git push -u origin master

pushエラー

push時に以下エラーとなるとき

remote: fatal: pack exceeds maximum allowed size

分割してpushする。以下は、リビジョンidまでのログをpushできる。

git push origin `git show リビジョンid | grep commit | cut -d' ' -f2`:refs/heads/master

リビジョンidは`git log`で確認できる。

参考:https://tsujitaku50.hatenablog.com/entry/2017/04/11/191821

フォーク解除

admin/Delete this repository

フォークして本体にマージする

  1. fork元にあるレポジトリのforkボタンを押す
  2. 自分のレポジトリにforkしたプロジェクトができる
  3. (任意)自分のプロジェクトにブランチを作成する
  4. (任意)作成したブランチでファイルを変更しpushする
  5. 自分のブランチから本体側にプルリクを出す(出せない場合はレポジトリ権限がない場合があるので見直す)
  6. 本体側でプルリクマージボタン押すと本体側にマージされる

リポジトリコピーからのコミット(ちょっと違うがsvnでいうチェックアウトなイメージ

git clone git@github.com:[user1]/[project1] [project1]
cd project1
git add hello.txt
git commit -m 'hellodesu'
git push

注:コメントがないと怒られます。

ファイル削除

git delete hello.txt

ファイル2回目以降コミット

git add -u
git commit -m 'adddesu'
git push

ファイル最新に

git pull

コマンド一覧

http://sourceforge.jp/magazine/09/03/16/0831212

リリースを作成する

タグでバージョンを作る

$ git tag -a v.1.0.0

タグ確認

$ git tag
v.1.0.0

タグをgithubへpush

$ git push origin v.1.0.0
  1. github.com側のreleaseページに移動
  2. v.1.0.0が存在することを確認
  3. "Draft a new release"ボタンを押す
  4. 画面のtag versionとtitleに"v.1.0.0"を入力
  5. 適切な変更点を下の欄に入れる

リリースを削除

$ git push origin :v.1.0.0
 - [deleted]         v.1.0.0

2段認証をonに

  1. githubの管理画面
  2. Account Settings/Set up tow-factor authentication

QRコード認証であれば

  1. Set up using an app

SMS認証であれば

  1. Set up using SMS


Permission denied (publickey).エラーが出る場合

sshの公開鍵がgithubのuserアカウントに登録されているか確認。

Username for 'ttps://github.com':が出る場合

remoteのurlがhttps担っている場合はsshに切り替える

githubのwikiをclone

git clone git@github.com:hogehoge/hoge.wiki

githubのwikiに画像を追加

例:helloworld.gitのwikiに画像を追加したい場合、以下imagesに追加する

$ git clone git@github.com:user1/helloworld.wiki
ls helloworld.wiki/images

記述

Markdown

![タイトル](ttps://github.com/user1/project1/wiki/images/Test.png)

HTMLのimg形式

<img src="ttps://github.com/user1/project1/wiki/images/Test.png" />

編集後、ttps://raw.githubusercontent.com/user1/project1/wiki/ な感じにドメインが修正される。

参考:https://howpon.com/8484

githubドメイン向けrsaの作り方

$ ssh-keygen -t rsa
~/.ssh/github_id_rsa
$ vi ~/.ssh/config
Host github.com
  HostName github.com
  IdentityFile ~/.ssh/github_id_rsa
  User user1
$ chmod 600 ~/.ssh/config

githubをwindowで使う

参考:http://wp.graphact.com/2011/02/07/github-windows-2011/

コードレビューをする

githubは`review changes`から何かチェックを入れないとコメントを残せない。

  • Comment: 軽微な指摘、コメント
  • Approve: 承認
  • Request Change: 修正依頼

コメント欄にある`Add Single Comment`を押せば、そのままコメントが残るっぽい。

プルリク時の画像登録

画像をドラッグすればよい。

プルリク時の画像リサイズ

<img src="画像url" width="300px" />

空のコミット

git commit --allow-empty -m "プルリクエストタイトル1"

wip開発などをするときに使う。更新するものがないと、プルリクできないので・・

Key is already in use エラーのとき

以下エラーのとき

Key is already in use

既に別アカウントで同じキーを持ってるので、別アカウントのキーを削除すればよい。

branchのネットワーク

以下に表示されてる

ttps://github.com/[user1]/[project1]/network

ソースの行数共有リンク

1-2行選択

ttps://github.com/[user1]/[project]/blob/master/test.txt#L1-%23L2