Git Tips

エイリアス

$ git config --global alias.co checkout
$ cat ~/.gitconfig
[alias]
    co = checkout

リモートURL

表示

$ git remote -v
origin  git@gitlab.com:foo/repo1.git (fetch)
origin  git@gitlab.com:foo/repo1.git (push)

切り替え

$ git remote -v
origin  git@gitlab.com:foo/repo1.git (fetch)
origin  git@gitlab.com:foo/repo1.git (push)
$ git remote set-url origin git@gitlab.com:foo/repo2.git
$ git remote -v
origin  git@gitlab.com:foo/repo2.git (fetch)
origin  git@gitlab.com:foo/repo2.git (push)

変更の退避

退避

$ git stash save

新規ファイルを含めて退避

$ git stash save -u

退避を取り出す

$ git stash pop

退避を適用

$ git stash apply

退避した一覧を表示

$ git stash list

退避した内容を確認

$ git show stash          # 直近
$ git show stash@{0}  # 直近
$ git show stash@{1}  # 直近の1つ前
$ git show stash@{2}  # 直近の2つ前

退避した特定のファイルを確認

$ git show stash:README.md

退避した新規ファイルを確認

$ git show stash^3

リセット

ローカルの最新にリセット

$ git reset --hard

リモートの最新にリセット

$ git fetch origin
$ git reset --hard FETCH_HEAD
($ git reset --hard origin/branch)

新規ファイルの削除

$ git clean -dfn     # dry-run
$ git clean -df
$ git clean -dfx     # .gitignore対象ファイル・ディレクトリも削除

プル

同一ブランチを複数人で編集する時などのプッシュ前に

$ git pull --rebase

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