When using sudo git add
command in Ubuntu, it caused the repository to be inaccessible without the sudo
prefix each time. This is because after using sudo, the regular user group loses the permission to operate. I found a solution on stackoverflow.
First, we need to know the id of our user and user group. Enter the following command in the terminal:
id -a
It will display the id of the user and group:
Next, we need to use the chown command:
cd .git/objects
ls -al
sudo chown -R uid:groups *
# Replace uid and groups with your own