Rename Git branch master to main


❯ git -v
git version 2.39.1

 

■ Delete local branch


git branch -d master

 

■ Rename local branch


git branch -m master main

 

■ Push the new branch, set local branch to track the new remote


git push -u origin main


git push --set-upstream origin main

 

■ Delete remote branch


git push origin :master


git push origin --delete master

I got this.


❯ git push origin :master
To https://github.com/your/project
 ! [remote rejected] master (refusing to delete the current branch: refs/heads/master)
error: failed to push some refs to 'https://github.com/your/project'

Switch default branch master to main at https://github.com/your/project

Rename Git branch master to main

 

■ Show status


❯ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean

❯ git branch -a
* main
  remotes/origin/main

❯ git branch -l
* main

❯ git branch -r
  origin/main

 

■ Conclusion



Repository default branch
Choose the default branch for your new personal repositories. You might want to change the default name due to different workflows, or because your integrations still require “master” as the default branch name. You can always change the default branch name on individual repositories.


👉 GitHub - Settings - Repositories hatena-bookmark

👉 Managing remote repositories - GitHub Docs hatena-bookmark


【Homebrew】git が2つある場合 【macOS】

git homebrew macos

👉 Re-installing Git on Mac OSX with Brew 

状況確認


~ % which git
/usr/local/bin/git

~ % git --version
git version 2.33.0

~ % which -a git 
/usr/local/bin/git
/usr/bin/git

~ % for i in $(which -a git); do echo -n "${i}:  "; ${i} --version; done
/usr/local/bin/git:  git version 2.33.0
/usr/bin/git:  git version 2.32.0 (Apple Git-132)

~ %  cat /etc/paths
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

~ % sudo rm -rf /usr/bin/git
Password:
rm: /usr/bin/git: Operation not permitted

私の mac には2つの git パッケージがインストールされている。


sudo rm -rf /usr/bin/git wont work for El Capitan due to SIP restriction

削除しようとしても macOS側の git は消せない。

通常、残しておくしかない。

対応方法

実行するときの git を Homebrew側に向けておく必要がある。

以下3つのどれかを、bash でも zsh でも起動スクリプトに追加する。


export PATH=$PATH:/usr/local/bin/git


export PATH=/user/local/bin:$PATH


alias git="/usr/local/bin/git"

AndroidStudio の git 不具合のときに少し気になったのでメモ。

👉 Cannot Run Git : Cannot identify version of git executable: no response – on startup 


Cannot Run Git : Cannot identify version of git executable: no response – on startup

よく出ますよね?

このダイアログ。

Cannot Run Git : Cannot identify version of git executable: no response – on startup

Cannot Run Git : Cannot identify version of git executable: no response – on startu

調べてみると、IDEA Intellij のバグトラッカーに issue があります。

Even if the CLT is installed, if the background process is heavy (for example, after booting your mac), typing "git --version" into the terminal may result in no response for several tens of seconds.

I've had this issue on Mac a few times after a reboot and auto-reopen of the previous windows.
Easy fix: quit IntelliJ with Cmd+Q and reopen it.

I got this on Windows after a restart. As Filippo says, restarting the IDE works as a fix.

👉 Cannot identify version of git executable: no response – on startup : IDEA-219762 

 

Git の設定

一応、Git の設定画面を見てみましょう。


[Preferences]

  ↓

[Version Control]

  ↓

[Git]

Cannot Run Git : Cannot identify version of git executable: no response – on startu

確認したら、IDE (AndroidStudio など) をリスタートです。

 

まとめ

IDE 再起動でダイアログは出なくなり正常に戻ります。

OS が忙しい時の Git コマンドのレスポンスの遅さが IDE に影響を及ぼしてるようです。

👉 【Homebrew】git が2つある場合 【macOS】