git remote add origin https://github.com/XXXXX/XXXXX.git
git push -u origin master
一度-uを付けてpushすればpush先が記憶されるため次回以降は基本的にgit pushのみでいける。
git remote add origin https://github.com/XXXXX/XXXXX.git
git push -u origin master
git stash
git stash pop
git push -u origin [new branch]
git clean --dry-run # -nでもOK。Untrackedファイルの確認。
git clean --force # -fでもOK。強制一括削除。
git clean --interactive # -iでもOK。対話的に個別削除。
~/work/awesome_events$git push別に何か対処した訳でもなく、あんたのブランチが古いからgit pullしてみろ、とヒントが書かれているので言う通り実行すると、 再帰的にマージしといたよというメッセージ。
To https://github.com/xxx/awesome_events.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/xxx/awesome_events.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
~/work/awesome_events$gi pull
-bash: gi: command not found
~/work/awesome_events$git pull
Merge made by the 'recursive' strategy.
~/work/awesome_events$
$ git branch new-branch origin/new-branch参考:
$ git checkout -b new-branch origin/new-branch #ブランチ作成後に移動
$ git config --global user.name "あなたの名前"Railsチュートリアルでは、長い予約コマンドのエイリアスを作っておくと便利だと書かれています。下記はcheckoutをcoとする例。
$ git config --global user.email your.email@example.com
$ git config --global alias.co checkout下記でgitコマンドの結果をカラー表示できる。
$ git config --global color.ui truegit configの設定値を確認するには-lオプション。
$ git config -l
$ git config --global core.editor "subl -w"アプリケーションのルートディレクトリでリポジトリの初期化。
$ git init
Initialized empty Git repository in /Users/mhartl/rails_projects/first_app/.git/
# Ignore bundler config.ファイルをGitに追加する。再起的に処理されるので、'.'であればルートディレクトリとそのサブディレクトリを含めて全てが対象となる。
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
# Ignore other unneeded files.
doc/
*.swp
*~
.project
.DS_Store
.idea
bundler_stubs/ #RVM使用時
$ git add .コミット前のファイルを確認するには、下記のgit statusコマンドを使う。
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: README.rdoc
# new file: Rakefile
$ git commit -m "Initialize repository"
$ git commit
$ git logその他にもこんな表示方法がある。
commit df0a62f3f091e53ffa799309b3e32c27b0b38eb4
Author: Michael Hartl <michael@michaelhartl.com>
Date: Thu Oct 15 11:36:21 2009 -0700
Initialize repository
$ git log --oneline # 1行ずつの簡易ログ表示
$ git log -p # 過去commitの詳細表示
$ git log -stat # 最新commitの統計的な変更状況表示
$ git diff # 最新commitと現在との内容比較
$ git diff --cached # ステージング後のファイルは--cachedオプションをつける
$ git rm index.html
$ git mv index.html index.html.erd
git fetch origin参考:
git reset --hard origin/master
git branch new-branch origin/new-branch参考:
$ git commit --amendコミットそのものを取り消してしまいたいときには以下を。これこれ。これがやりたいこと。HEADを一つ前のコミット時に移動させる意味?
$ git reset --soft HEAD^下記でコミットと合わせてファイルの修正点も以前の状態に戻るようです。
$ git reset --hard間違ってresetしちゃった!ってときはORIG_HEADでreset前に戻れる。
$ git reset ORIG_HEAD下記の記事はHEADの意味も含めてわかりやすかった。
% git checkout -fタイトルとコマンド一行、なんてエントリーが増えるかもしれない。
git clean --dry-run #確認参考:
git clean -f #削除