LoginSignup
1
1

More than 5 years have passed since last update.

個人的によく使うGit操作まとめ

Last updated at Posted at 2018-06-22

はじめに

自分用メモなので自分が使わないもの、やり方を覚えているものは書きません。

リモートブランチを新規にローカルに持って来る

git branch [new_branch] [remote/new_branch]
git checkout -b [new_branch] [remote/new_branch]

リモートで消したブランチがgit branch -aをやったときに残ってる場合

git fetch --prune

で同期すればOK

.gitignoreを編集したのにファイルが消えない場合

git rm -r --cached [file_path]
git add .
git commit -m "Update .gitignore"

上記一行目でキャッシュを消す。

すべてのファイルのキャッシュを消したい場合

git rm -r --cache .

ブランチをリネームしたい

git branch -m [old_branch_name] [new_branch_name]

  
カレントブランチの名前を変えたい場合

git branch -m [new_branch_name]

強制的にブランチを消したい時

git branch -D [branch_name]

強制的にリモートにプッシュしたい時

git push -f origin [branch_name]

ローカルをリモートで上書きしたい時

git fetch origin
git reset --hard [origin/branch_name]

リポジトリごとにユーザを設定したい

git config --local user.name "name"
git config --local user.email "example@mail.com"

普通に全体として登録する場合は --local--global

リモートリポジトリのURLを変更する

git remote set-url origin [new_url]

現在のURLを確認

git remote -v
1
1
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
1
1