Search code examples
gitrustrust-cargohelixstarship

zmk-config git branch is head for new cargo projects in non-parent directory


Problem:

I have a zmk-config dir in ~/zmk-config, which is also a git repo. This repo seems to be the head of every new git repo I create, even in different/non-child dirs.

Ex:

~
-> pwd
/Users/uname

-> cd ~/zmk-config
zmk-config on branch zmk-config

-> git show 
commit a1... (HEAD -> zmk-config)
    
    trying to change head
...

-> cd ~/rust
/Users/uname/rust

-> cargo new vcs_test
building...

-> cd vcs_test
vcs_test on branch zmk-config
v1.78.0 -> 

I was expecting:

-> cd vcs_test
vcs_test on branch vcs_test

I have tried removing .git from both repos and re-initializing, but I still encounter the error when building a new rust project with cargo.

I have tried git reset in both repos, and that hasn't fixed the issue either.

Using cargo new vcs_test --vcs none does not fix the issue.

I am new/learning rust and cargo, and I know very little about git.

I am using starship terminal emulator, and my editor is helix with rust-analyzer LSP.

Thanks for any tips in advance. I am not sure where to start with troubleshooting this issue.

UPDATE: from directory ~/rust/vcs_test

v1.78.0 -> git config --list --show-origin
file:/opt/homebrew/etc/gitconfig        credential.helper=osxkeychain
file:/Users/james/.gitconfig      user.name=james
file:/Users/james/.gitconfig      [email protected]
file:/Users/james/.gitconfig      init.defaultbranch=zmk-config
file:.git/config        core.bare=false
file:.git/config        core.repositoryformatversion=0
file:.git/config        core.filemode=true
file:.git/config        core.ignorecase=true
file:.git/config        core.precomposeunicode=true
file:.git/config        core.logallrefupdates=true

This shows that the init.defaultbranch=zmk-config directory is zmk-config. Does anyone have any tips to change this behavior?


Solution

  • FIX:

    -> git config init.defaultBrach master
    
    -> cd ~/rust
    
    ~/rust
    -> cargo new vcs_test
    Building...
    
    -> cd vcs_test
    
    vcs on master
    v1.78.0 -> git config --list --show-origin
    ... init.defaultbranch=master