git commit -m "add test.txt": fatal: Unable to create 'test/.git/indexlock': Permissions denied

Bit-10101

Member
Joined
Nov 30, 2021
Messages
52
Reaction score
8
Credits
442
I have create a folder called test witH
sudo mkdir test
After that I´ve created a file test.txt within that folder.
Now I want to ADD this file to Git Repository
git commit - "add test.txt"
Then i get
****please tell me how you are** bla, bla..no commits yet

The I specify my e-mail and user like this:

git config --global user.name "myAccount" git config --global --add user.emial "[email protected]"


But when I want to check the config
git config --global --list:
user.name=myAccount
user.e-mail=[email protected]


Now I Run into trouble with his comand:
git commit -m "add test.txt"

error: fatal: Unable to create 'test/.git/indexlock': Permissions denied

I'm working with LinuxMInt 20.2 as client
 


f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
4,453
Reaction score
3,163
Credits
32,290
You created the directory with sudo meaning the directory is owned by root. Try chowing it with your username, so like this.
Code:
sudo chown username:username -R test
If that doesn't work also chown the .git dir recursive.
Code:
sudo chown username.username -R test/.git
[CODE]
 
OP
B

Bit-10101

Member
Joined
Nov 30, 2021
Messages
52
Reaction score
8
Credits
442
I have create a folder called test witH
sudo mkdir test
After that I´ve created a file test.txt within that folder.
Now I want to ADD this file to Git Repository
git commit - "add test.txt"
Then i get
****please tell me how you are** bla, bla..no commits yet

The I specify my e-mail and user like this:

git config --global user.name "myAccount" git config --global --add user.emial "[email protected]"


But when I want to check the config
git config --global --list:
user.name=myAccount
user.e-mail=[email protected]


Now I Run into trouble with his comand:
git commit -m "add test.txt"

error: fatal: Unable to create 'test/.git/indexlock': Permissions denied

I'm working with LinuxMInt 20.2 as client
You created the directory with sudo meaning the directory is owned by root. Try chowing it with your username, so like this.
Code:
sudo chown username:username -R test
If that doesn't work also chown the .git dir recursive.
Code:
sudo chown username.username -R test/.git
[CODE]

IT´s sounds logical that I created the folder called test and a text file with root permission
and do not have permission as regular users.

So, I´ve executed as regular user:
[email protected]: dir (and these are the folders)
bin cdrom, dev, home, test and so on..
After that I´ve run:
a) [email protected]:/$ sudo chown myAccount:myAccount -R test
b) [email protected]:/test$ git commit -m "add test.txt"
After that I got the message:
On branch master
nothing to commit, working tree clean

(but I know there is a file test.txt within folder test, see below)
[email protected]:/test$ Dir
test.txt
What could possible cause the problem?
Really appreciate your answer

Ps.
I have from the beginning created a local git repository

2021-12-09: Update, did run this:
Change permissions on my folder test to 777, so myAccount have full acess.
But still:
[email protected]:/test$ git commit -m "add test.txt"
On branch master
nothing to commit, working tree clean

:)
 
Last edited:

f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
4,453
Reaction score
3,163
Credits
32,290
I2021-12-09: Update, did run this:
[email protected]:/$ git init
/.git: Permission denied
Is a permission problem, you're user doesn't have write access there, it even shows you the directory
/.git: Permission denied
Try to delete that directory first.
Code:
sudo rm -rf test
mkdir test
cd test
git init
 
Last edited:

dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
1,318
Reaction score
948
Credits
7,826
On a somewhat related note, do you know of any good gitgui's?
Yes, I googled, yes I downloaded some of them, but most don't work at all,
some don't take token credentials, and some are difficult to use.

Just looking for a recommendation.
 

f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
4,453
Reaction score
3,163
Credits
32,290
On a somewhat related note, do you know of any good gitgui's?
I don't know any I have only used the git command-line tool, why would you need a GUI for git? If you don't understand the concepts behind git a gui isn't got to change that?
 

ajstewart_lang

New Member
Joined
Aug 26, 2021
Messages
10
Reaction score
9
Credits
83
I don't know any I have only used the git command-line tool, why would you need a GUI for git? If you don't understand the concepts behind git a gui isn't got to change that?
+1 for not going down the GUI-y route - command line git is the way to go and there are lots of great resources out there incl. this great Software Carpentry one: https://swcarpentry.github.io/git-novice/
 

dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
1,318
Reaction score
948
Credits
7,826
I don't know any I have only used the git command-line tool, why would you need a GUI for git? If you don't understand the concepts behind git a gui isn't got to change that?

LOL, it isn't for me. But we have a jump box the dev's use. There is no CLI.
We can give them links to GUI apps, but not allowed to give them access to CLI.

Not my requirement, I just work here.
 
OP
B

Bit-10101

Member
Joined
Nov 30, 2021
Messages
52
Reaction score
8
Credits
442
Have you remembered to stage your changes before trying to commit them?

So, something like:

Code:
git add test.txt
git commit -m "<insert commit message here>"

then
Code:
git push
if you're trying to push to somewhere like GitHub or GitLab.
I does now, thanks, for a clear and serious answer.
Is a permission problem, you're user doesn't have write access there, it even shows you the directory

Try to delete that directory first.
Code:
sudo rm -rf test
mkdir test
cd test
git init
It worked
-Thanks for a clear and serious answer.
 
OP
B

Bit-10101

Member
Joined
Nov 30, 2021
Messages
52
Reaction score
8
Credits
442
I does now, thanks, for a clear and serious answer.

It worked
-Thanks for a clear and serious answer.
Oh no,that was a short time of happiness know I´m back to that frustrating message:
[email protected]:/test$ git status
On branch master
nothing to commit, working tree clean


2021-12-18: Update Note:
Before I ran git status I executed this:
[email protected]:/test$ git commit -m "add test.txt"

Explanation found with Google:
Git is a distributed version control system. This means you can maintain multiple separate copies of a repository.
Because multiple copies of a repository can exist, different developers can work on their own version of a repository locally. Then, when they have finished making a change, they can push their changes to the main version of the repository.

The “nothing to commit, working directory clean” message tells us all of the changes we have made to a Git repository are committed. This means the current state of our project folder is exactly the same as that of the last commit.


-So, think the message is normal?, but I´ve not pushed anything yet
 
Last edited:

f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
4,453
Reaction score
3,163
Credits
32,290
You need to add a file first before it sees it.
Code:
cd test
touch test.txt
git add test.txt
git status
git commit -m "add test.txt"
 
OP
B

Bit-10101

Member
Joined
Nov 30, 2021
Messages
52
Reaction score
8
Credits
442
Yes, thats why I asked the question, this is exactly what I´m doing, so I wonder if this message is "normal"
In other words there is nothing to commit because nothing has happen. But the problem is that I always get this message.
On branch master
Nothing to commit, working tree clean.

Please, see screenshot
[email protected]:
git_commandJPG.JPG


New try:
a) Ive created a new file called test2.txt and run git status I get:
"Changes to commited:
(use "git restore --staged <file>.." to unstage)
New file: test2.txt

b) So, im trying this command:
git commit -m "add test2.txt"

[master bla, bla] add test2.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test2.txt

c) [email protected]: git status
On bransch master
nothing to commit, workin tree clean


Same message again.
 
Last edited:

f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
4,453
Reaction score
3,163
Credits
32,290
Try creating a directory instead, what happens then?
Code:
cd Test
mkdir testdir
git status
 

f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
4,453
Reaction score
3,163
Credits
32,290
The only other thing I can think of that you added something to your git configuration that makes it act like this. Share the output of the following?
Code:
cat ~/.gitconfig
 

JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,451
Reaction score
2,056
Credits
10,088
-So, think the message is normal?, but I´ve not pushed anything yet
Yes, this is normal. It just means that your local working tree is clean and up to date. In other words, you don’t have any files in the branch with uncommitted changes.

But at this point - the changes are only in your local repository.

WRT pushing - that involves pushing committed changes from your local, working copy of the repository to a remote repository.

For that you will need a repository set up on a remote (or local) server, running a service like GitHub/gitlab. That repository needs to be set up as a "bare" repository, which is one you cannot directly make commits to - you can only push changes to it and/or pull changes from it.

Do you have a remote already set up?
What is the output of the command:
Bash:
git remote --v

If you don't have a remote set up already, I made this post a while ago, which explains the process:
The above post only applies if this is your own project though.

So, for example - you’ve been working on a project locally, using git and you want to set up a remote, to allow you to push to a repository hosted on GitHub, Gitlab, or some other git hosting service.
I personally use notabug.org.

If you’re forking and making changes to a third party’s project, the process is slightly different.

And you don’t even have to set up a remote at all. You could just keep your project under a local git repository and leave it at that.

I have a number of personal projects that are only in local repositories. But doing this means having to make regular backups. Or at least backing up the project every time you commit any changes to it!

Having a remote set up is more convenient.
Your remote basically is your backup and master repository all in one. It also means that as long as you have an internet connection - you can quickly clone your project on any of your devices (or even somebody else’s!).
You can ‘git clone’ locally, from your remote repo, commit some changes locally, push them back upstream to your remote and then delete the local clone, if need be!
 

f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
4,453
Reaction score
3,163
Credits
32,290
Yes, this is normal. It just means that your local working tree is clean and up to date. In other words, you don’t have any files in the branch with uncommitted changes.I find it a bit odd though because when I create new directory and run git init, then create a directory or file my test git repo sees the changes.
Code:
mkdir test
cd test
git init

touch testfile.txt
mkdir testdir
touch testdir/testfile2.txt

 git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    testdir/
    testfile.txt

nothing added to commit but untracked files present (use "git add" to track)

git add testdir testfile.txt

 git status             
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
    new file:   testdir/testfile2.txt
    new file:   testfile.txt

 git commit -m "commit test files and test directory"
[master (root-commit) 0031cf0] commit test files and test directory
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 testdir/testfile2.txt
 create mode 100644 testfile.txt

git status                                     
On branch master
nothing to commit, working tree clean

git remote -v 
(No output because I didn't add any remotes)
 

JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,451
Reaction score
2,056
Credits
10,088
The only other thing I can think of that you added something to your git configuration that makes it act like this. Share the output of the following?
Code:
cat ~/.gitconfig

@Bit-10101
Additionally, if you use the command:
Bash:
git log
It should list the commit history of your repo. So you should be able to see any commits you’ve made.
Which from what I can see, should be two commits. The first being where you added test.txt and the second where you added test2.txt.

Also, git isn’t flagging the new directory you added because it is empty.
If you create a couple of files in the directory and then run git status it will flag the files in the sub-directory as untracked!
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!


Latest posts

Top