LoginSignup
6
5

More than 5 years have passed since last update.

リモートリポジトリとローカルリポジトリを強制一致させる方法

Posted at

リモートリポジトリのブランチの状態をそっくりそのままカレントブランチに適用したい時に行う方法。
現状これが一番安全なのではと思うので書き残しておく。

この他に何かいい方法があれば教えてください。

# 追跡ブランチの更新
git fetch
# untrackedなファイルを作業スペースから削除
git clean -fdx
# to be committedなファイルを作業スペースから削除
git reset --hard HEAD
# 追跡ブランチをcheckout -Bする
git checkout -B master origin/master

git checkout -bではなく-Bにする事で既にローカルにブランチがある状態だと、
ブランチをリセットして指定したブランチに再構築してくれるそうです。

参考)
http://git-scm.com/docs/git-checkout

If -B is given, <new_branch> is created if it doesn’t exist; otherwise, it is reset. This is the transactional equivalent of

$ git branch -f <branch> [<start point>]
$ git checkout <branch>

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5