25
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Githubのブランチ名 変更手順

25
Last updated at Posted at 2019-11-05

Githubのブランチ名は変えられる

Githubを利用しているとたまにアルファベットの綴りを間違えたり、「色々とブランチ名と関係ないファイル触りすぎて、ブランチ名と変更内容があっていない。。。。」ということはありませんか?この記事ではターミナルを使った簡単なブランチ名変更手順をお伝えします。

基本的な手順としては

1.ブランチ名を確認する

該当するディレクトリに移動し、以下の2通りの方法で確認。

自分が切ったローカルにあるブランチ名のみ

$ git branch

チーム開発などで他の人が切ったリモートを含めた全ブランチ名

$ git branch -a

terminal
$ git branch -a

  /ローカル、リモートのブランチが全て確認できます/
  gh-pages
  master
* message-view (現在作業中のブランチ)
  remotes/origin/gh-pages
  remotes/origin/message-view
  remotes/origin/master

今回の場合であれば、
ブランチ名: message-view を tweet-viewに変えたい。
とすると

2.ブランチ名を変更する

$ git branch -m 変更前ブランチ名 変更後ブランチ名

terminal
$ git branch -m message-view tweet-view 

3.リモートの変更前ブランチを削除する

$git push origin :変更前ブランチ名

terminal
$ git push origin :message-view

4. 変更したローカルの新しいブランチ名をリモートにpushする

$ git push origin 新しいブランチ名

terminal
$ git push origin tweet-view

これでOK。
再び、git branch -aなどで確認するとリモートとローカルで名前がともに変更されているはずです。

25
23
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
25
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?