Git, having permission issues pushing - linux

So I'm brand spanking new to Git and development in general. I'm a Linux and Mac user on a few different machines and have a couple cloud servers with AWS, I work on small little python projects on all of them.
I'll try to explain what I want first, hopefully I'm close to having the best solution that will work for my use case. I want to be able to write code on whatever device I own, Ubuntu desktop at home, work Macbook, cloud servers, Ubuntu desktop at work, and a personal Macbook. Obviously I'm working with different hostnames and usernames, I'm the only one that works on my code.
I went through the git guide and it's working, sort of. I tried to setup my repository on my cloud server which I will also be changing code on. I've been trying to commit and push from my Macbook but have been getting a string of permission errors all day, I've been having to go back to the repo and chown -R as my ssh wheel user since every object there is getting overwritten as root.
Here are some sample error messages I'm seeing when trying to push from my macbook:
A commit:
macbook:dev macbookuser$ git commit
# On branch master
# Your branch is ahead of 'origin/master' by 6 commits.
#
nothing to commit, working directory clean
And then the push:
macbook:dev macbookuser$ git push
user1#myserver-aka-repo.com's password:
Counting objects: 18, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (12/12), done.
Writing objects: 100% (14/14), 1.62 KiB, done.
Total 14 (delta 7), reused 0 (delta 0)
error: insufficient permission for adding an object to repository database ./objects
fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit
To user1#myserver-aka-repo.com:/home/myserver-aka-repo/dev/.git
! [remote rejected] master -> master (n/a (unpacker error))
error: failed to push some refs to 'user1#myserver-aka-repo.com:/home/myserver-aka-repo/dev/.git'

If the chown and umask 0002 don't fix this on the server, make sure the repo you are pushing to has been shared with the right mode.
git config core.sharedRepository
See "Git Push Error: insufficient permission for adding an object to repository database" for more on this option.
I usually set core.sharedRepository to umask, and set my umask to 0002.

Related

Android Studio GitHub: push to origin/master was rejected

I have shared my project to GitHub. I have just started using GitHub and I am not knowledgeable about Git in general, just following online tutorials. Each time I push to GitHub I get an error: push to origin/master was rejected. I searched online and, as I understand it, the files in the remote repository must have changed. But I am the only one connected to my repository and it is set to Private.
I did not change the files in GitHub and no one could have changed it. But each time I make edits to my local files in Android Studio and push it, I always get the same error.
P.S.: I'm using the GUI, not the Terminal.
I tried deleting my repository, shared my local project again, update my code, then push, but I get the same error, again.
Same happened to me. Seems the problem could be there are some files in your GitHub repository.
Create a new blank repository on Git.
On Android Studio you need to VCS -> Import into version control -> Create Git Repository...
If above works, Commit and Push your files to GitHub.
If not, create a backup of your source code folder.
After that rename your folder.
Copy your files into the recently created new folder (except the .git sub-directory)
Try again with the VCS -> Import into version control -> Create Git Repository... to the new folder.
It worked for me before some attempts and I could Push my work to GitHub. Hope it helps.
Lets say your branch name is name_of_branch
In case if you see a Git -> Console -> log message saying.
refs/heads/name_of_branch:refs/heads/name_of_branch [remote rejected]
(cannot lock ref 'refs/heads/name_of_branch': 'refs/heads/name' exists;
cannot create 'refs/heads/name_of_branch'
This means there is some issue with branch name somehow. I solved it by renaming my branch.
VCS -> Git -> Branches -> select your branch and rename
I had such an issue too and I clicked the tab of Git on the lower left of Android Studio and then selected "console", I saw [remote rejected] (push declined due to email privacy restrictions).
I then referred to the following thread:
Error "Your push would publish a private email address"
-----------Addition------------
The error message could also look like this:
Successfully created project '(your project name)' on GitHub, but initial push failed: Enumerating objects: 10, done. Delta compression using up to 4 threads Total 10 (delta 0), reused 0 (delta 0), pack-reused 0 remote: error: GH007: Your push would publish a private email address.
or
remote: You can make your email public or disable this protection by visiting: remote: http://github.com/settings/emails failed to push some refs to 'xxx.git'

Merged code from repo not updating in production server after push

I have a post-receive hook in my server.
I also have a remote repo(origin) (branch:stage) where another developer pushes to.
I pull the commits and push them to production from my local computer.
I recently created a new branch(feature) from the latest head of the existing branch(stage), added some code and pushed the feature branch to remote repo. I merged the new features from feature branch to stage branch.
Then I pulled from the remote repo to local.
Now, I pushed the stage branch to production.
My post-receive file consists:
git --work-tree=/path/to/project --git-dir=/path/to/project.git checkout -
f stage
My head in the remote repo after merge is currently at ae228b9.
And, at the remote production hook's latest logs also points to ae228b9.
The problem is that the code from the merge are not seen in the production server.
Do I have to do something else to get the merged code to production?
After I pulled from origin and pushed to production, I tried changing the new files locally, committed them and push to the server. But, the changes are not reflected in the server.
Edit:
Also, I uninstalled apache php mysql and installed them again. Before the unistallation/installation, the home page was showing in server but the routes were not working(404 error) but the git hook was working. After the unistallation/installation, the git hook stopped working
Update:
I created a new hook with the same code as above. Now during the push I get:
remote: error: unable to unlink old '.gitignore' (Permission denied)
remote: error: unable to unlink old '.htaccess' (Permission denied)
remote: fatal: cannot create directory at '.idea': Permission denied
I tried the following code inside my project folder and project.git(hook) folder:
sudo chmod -R ug+w .;
unable to link
after which the push is a success but the changes are not reflecting.
I solved this by deleting the contents of the project folder and pushing again with some new changes.
I faced the same issue(Azure deployment)
There are two ways to ways to handle this -
Increase timeout setting (but deployment may stuck some times)
Push new changes (redeployment)
I prefer 2nd option.

Gitea can't fetch repositories

I installed gitea (If someone don't know it, it's an opensource fork of gogs) on my raspberry pi. I tried it under user pi and under user git. In user pi the gitea was installed in /home/pi/gitea and in git it was installed in /home/git. In both situation the repository directory was in the install root.
I made a new repository with the webui and I tried 2 remotes with both installation.
rpilocal = pi#192.168.1.125:/home/pi/gitea/repositories/uname/repositoryname
rpilocal2 = pi#192.168.1.125:uname/repositoryname
rpigitlocal = git#192.168.1.125:/home/pi/gitea/repositories/uname/repositoryname
rpigitlocal2 = git#192.168.1.125:uname/repositoryname/repositoryname
When I tried to push on rpilocal2 and on rpigitlocal2 I got the following error message:
git push rpigitlocal2 master
git#192.168.1.125's password:
fatal: 'feralheart/leltar.git' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
and when I tried to push with rpilocal and rpigitlocal the push was success, BUT in the webinterface I stil got the "Make a new repository or push existing with CLI".
What's the matter?
I was working-with a test setup of gitea on a VPS♣ and encountered what may have been the same problem. After poking around with various tests, I found a workaround that is working for me. In case it could help you...
What was already working
In my case, asking gitea to create a new git repository with an initial "readme commit" was working fine. I could clone, add new commits, and push. The new commits appeared after the first one in the gitea web UI.
What wasn't working
If I asked gitea to create a repository without an initial commit†, gitea's web UI would not reflect the push of a commit history, i.e.
user#client:~/projects$ mkdir myCode
user#client:~/projects$ cd myCode
user#client:~/projects/myCode$ git init
Initialized empty Git repository in /home/user/projects/myCode/.git/
user#client:~/projects/myCode$ echo "testing 1 2 3" > file.txt
user#client:~/projects/myCode$ git add file.txt
user#client:~/projects/myCode$ git commit -m0
[master (root-commit) f9d8e7] 0
1 file changed, 1 insertion(+)
create mode 100644 file.txt
user#client:~/projects/myCode$ git remote add origin git#server:gitea_repos/owner/myCode.git
user#client:~/projects/myCode$ git push -u origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 210 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git#server:gitea_repos/owner/myCode.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
user#client:~/projects/myCode$
git would report success and git#server:gitea_repos/owner/myCode.git would continue to function as a remote but the gitea web UI would continue to display the "empty repository" help page instead of the repository browser‡.
Work-around strategy
Because new commits were registering on repositories that started non-empty, it occurred to me that gitea might notice the change if git overwrote the stub commit history of a new project with the complete commit history of another project↯. To try this, follow:
3 Easy Steps:
In the gitea web UI, create a new repository. On the New Repository creation page, be sure to check the box next to Initialize this repository with selected files and template before clicking Create Repository.
On your workstation, add this new stub as a remote to the local git repository with the desired commit history.
user#client:~$ cd projects/myCode
user#client:~/projects/myCode$ git remote add gitea git#server:gitea_repos/owner/myCode.git
Overwrite the gitea-generated stub-commit with the intended material.
user#client:~/projects/myCode$ git push -fu gitea master
Counting objects: 97, done.
Delta compression using up to 32 threads.
Compressing objects: 100% (95/95), done.
Writing objects: 100% (97/97), 55.53 KiB | 0 bytes/s, done.
Total 97 (delta 45), reused 0 (delta 0)
To git#server:gitea_repos/owner/myCode.git
+ a1b2c3...d4e5f6 master -> master (forced update)
Branch master set up to track remote branch master from gitea.
user#client:~/projects/myCode$
Note that, for Step 3:
-f is for force: this empowers git to perform the (otherwise prohibited) "commit tree overwrite"
-u is for set-upstream - this connects local branch master through the remote-tracking branch gitea/master to the master branch managed by gitea
Follow through
This strategy is something of a hack and I suspect it leaves a few things undone. E.g. you might want to push branches and tags up to gitea. (My tests haven't taken me this far.) Consider --all for branches and --tags for tags:
user#client:~/projects/myCode$ git push gitea --all
user#client:~/projects/myCode$ git push gitea --tags
While YMMV, I wish you luck!
Footnotes:
♣ - I am working with gitea-1.4.2-linux-amd64 on Ubuntu 16.04.2 LTS hosted at virmach.com.
† - git uses the term "empty repository" when referring to a repository w/o commits but, in the internal API used by gitea to access git features (and, occasionally, by gitea community members), the term "bare repository"☥ is used.
☥ - git uses the term "bare repository" when referring to a repository not embedded (as the directory ./.git) in the root directory of a "working tree". Bare repositories are frequently used as a canonical copy for collaboration and are stored on (and accessible from) a server. E.g. the 'github' service. Sometimes these directories are named with the schema project_name.git
‡ - I tried a number of setup variations, asked around on irc channel #gitea, and poked around in the code. All I can conclude is that some difference in the git→hooks→gitea chain (varying between empty and non-empty repositories) is responsible for this problem on my VPS.
↯ - Before this, I thought of replaying the history of the desired project over the new stub but this rebase operation is a desperate hack: all the commits get new sha checksums and, essentially, all developers would have to clone-in again as if working on a new repository.

Git Initial Push Bad File Descriptor Error

I am new to git and have been following various tutorials on setting up a centralized git server. For the past few days, I have been having trouble with the following error message:
Counting objects: 59, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (59/59), done.
Writing objects: 100% (59/59), 525.33 KiB | 0 bytes/s, done.
Total 59 (delta 15), reused 0 (delta 0)
remote: fatal: failed to read object 24e3826fe4be7dbaddbfcd698e943b5b8f9598ec : Bad file descriptor
error: unpack failed: unpack-objects abnormal exit
To ssh://git#[server url]/volume1/git/[project name]
! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to 'ssh://git#[server url]/volume1/git/[project name]'
Initially, I used GitEye on my client side to manage git repository, but I encountered the problem when I tried to push my first commit to my linux server. So I played around with the permission and set the ownership of the whole git directory recursively to user "git". Nothing works. So I tried cloning a bare repository from the server and then try the push, but that didn't work either...returning me with unpacker error.
So I switch my software to Git Extensions and also trying the push on Git Bash...still the same error. Oh, forgot to mention that in the process, I deleted my local and remote git repository various times.
While one may argue that this may be a duplicate of git push over sshfs failing with “error when closing sha1 file: Bad file descriptor”, but I don't use sshfs and I am running Windows on my client side.
This may be a duplicate of Git push error - fatal: file '' write error: Bad file descriptor, but the push never works before.
UPDATE:
With mentioning about the version, I wonder if the version mismatch between the server and the client is the source of the problem. So I downgrade my client git version from 1.9.4 to 1.8.4.msysgit.0, but still found the problem after deleting and recreating a new git repository.
What interesting though is that I also tried to copy manually the git repository from the client to the server and do a git status on the remote side. As a result, I encounter the bad file descriptor, but that error didn't appear on the client side.
I found the source of the problems. I tried to do a first commit on my remote side and I got "not a valid object" error. Thus, I have a bad git build on my remote side. Thanks for your guidance. It points me the right path to look.
Now I have to figure how to get a newer (or different) version of git for my remote platform without having to use ipkg.

Can't push to git repository as normal user

There are a couple good posts on this subject, but I am not sure if they apply to my circumstances.
Error pushing to GitHub - insufficient permission for adding an object to repository database
Git Push Error: insufficient permission for adding an object to repository database
When performing a push as a normal user, I receive the following error:
remote: error: insufficient permission for adding an object to
repository database ./objects
Note that I can push if I am logged on the local machine as root. I see from the below that the origin is git#easybbb.com:root I don't know if it matters, but the remote repository I am trying to push to is hosted by me using GitLab.
The local git directory is 0775 and belongs to group "www", I've executed chmod -R g+rwxs /var/www/ to ensure that new files are of group "www", the normal user that is trying to push belongs to group "www", and I've executed git config core.sharedRepository group.
How do I fix this error?
git push origin master
Counting objects: 11, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 487 bytes | 0 bytes/s, done.
Total 6 (delta 5), reused 0 (delta 0)
remote: error: insufficient permission for adding an object to repository database ./objects
remote: fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit
To git#easybbb.com:root/bidjunction.git
! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to 'git#easybbb.com:root/bidjunction.git'
git remote -v
origin git#easybbb.com:root/bidjunction.git (fetch)
origin git#easybbb.com:root/bidjunction.git (push)
It has nothing to do regarding the many similar questions. The key is "remote: error: ". The problem is the remote repository (GitLab which is similar to GitHub). Making all associated files owned by git solved the problem.

Resources