-2

Reviewed related articles on SO with no success.

I'm on macOS:

Installed Rust OK:

rustup update nightly
rustup update stable
rustup target add wasm32-unknown-unknown --toolchain nightly

Then installed this:

XX-MacBook-Air-2 substrate-node-template % git clone -b v2.0.0 --depth 1 https://github.com/substrate-developer-hub/substrate-node-template
Cloning into 'substrate-node-template'...
remote: Enumerating objects: 46, done.
remote: Counting objects: 100% (46/46), done.
remote: Compressing objects: 100% (42/42), done.
remote: Total 46 (delta 0), reused 29 (delta 0), pack-reused 0
Receiving objects: 100% (46/46), 69.55 KiB | 962.00 KiB/s, done.
Note: switching to '655bfdc6fc922d117849cbcf808ee5bf2dfa1d53'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

Then this:

cd substrate-node-template/ 

and this:

XX-MacBook-Air-2 substrate-node-template % git checkout -b my-first-substrate-chain 

fatal: cannot lock ref 'refs/heads/my-first-substrate-chain': Unable to create '/Users/patrickburns/substrate-node-template/.git/refs/heads/my-first-substrate-chain.lock': Permission denied

Any thoughts on how to resolve this error are greatly appreciated.

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
Mountaineer
  • 7
  • 1
  • 2
  • The error message says, among others: "If you want to create a new branch to retain commits you create, you may do so (now or later) by using -c with the switch command.". – 9769953 Apr 29 '21 at 23:56
  • The first prompt indicate you could have executed the commands in the same directory twice. `XX-MacBook-Air-2 substrate-node-template %` maybe you have a directory `substrate-node-template/substrate-node-template/` containing the code. – Simson May 19 '21 at 03:39

3 Answers3

5

You’re having a permissions problem. But you haven't said anything that would indicate why.

I did what you did, as far as Git is concerned, and had no difficulties at all:

$ git clone -b v2.0.0 --depth 1 https://github.com/substrate-developer-hub/substrate-node-template
$ cd substrate-node-template/
$ git checkout -b br
Switched to a new branch 'br'

The fact that you can't do that suggests that you've somehow cloned this repo into a place where you don't have permissions. But we can't tell you, from here, why that is.

matt
  • 515,959
  • 87
  • 875
  • 1,141
1

You haven't the rights to write / modify something in the .git folder where git store the local state of your files (which is used to sync with the repo)

I'll provide you the solution but before doing it you must think because you could have some unwanted effects.

Go first to the folder where you do the git cmd then use

ls -la

You should have the list of files with owner/group for each file.

Look the owner/group of .git folder (should be you) and update owner/group of folder and content with yours.

So if the user/group is myuser mygroup for .git folder you can do

chown -R myuser:mygroup .git

It will update the owner and group for .git and recursively for the files and folders in .git folder.

Now you should be able to use your git command (if the current user is the one owning the git folder and child files/folder)

Ice2
  • 166
  • 1
  • 7
0

It is bound to related to the git, but not substrate. try some command based on your situation.

rm .git/refs/remotes/origin/main 
git fetch
git gc --prune=now
git remote prune origin

Usaully command push will work so in catch it is better delete ./.git and then take a pull again.

At last it may be cause of submodules so try to make a new repository with new remote address.