Git備忘録

git-icon Git

ファイル操作

ファイルの状態を確認

git status

コミットしたいファイルを追加

git add .

コミットしたいディレクトリを指定して追加

git add ディレクトリ名

ローカルにコミットする

git commit -m "コメント"

branchの操作

ブランチの一覧を見る

git branch -a

新しいブランチを作る

git branch 作成するブランチ名

新しいブランチを作って移動する

git branch -b 作成するブランチ名

ブランチの切り替え

git checkout ブランチ名

ブランチをリモートに登録する

git push -u origin 登録するブランチ名

ブランチをリモートにプッシュする

git push origin master

もしくは

git push origin ブランチ名

リモートからマージしたファイルを取得する

git pull origin ブランチ名

編集内容を元に戻す(addする前)

[git] 戻したい時よく使っているコマンドまとめ - Qiita
はじめに コミットのバージョンを戻す、ステージングしたものを編集内容ごと取り消す、ファイルのステージングを取り下げる...と戻すにも色々あります。 整理も兼ねて業務でよく使っているコマンドをまとめます。 目次 編集内容...

エラー

git push の reject

出たエラー内容

To git@github.com:◯◯◯.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:◯◯◯.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

原因

自分がリモートを pull してその変更を push するまでの間に、元々のリモート内容に変更があった場合に出る。

解決法

git pull でマージしてから、再度 push する。

git pull origin master

コメント

タイトルとURLをコピーしました