github push difficulties for new repository - github

I have attempted to add a new repository to github per their usual instructions with an odd rejection...
Owner#Owner-HP ~/Bescrewed
$ git push -u origin master
ERROR: Permission to TangibleDream/Bescrewed.git denied to TangibleDream/demo_app.
fatal: The remote end hung up unexpectedly
Owner#Owner-HP ~/Bescrewed
The problem is, demo_app was my last repository. The one I'm doing presently is bescrewed and should be in no way connected to demo_app.
Has anyone had this issue before?

It might be tied to an ssh issue as described in GitHub help page:
Permission to user/repo2 denied to user/repo1
This error occurs when you attach your key as a deploy key on repo1.
You can push and pull from that repo without issue, but you won’t have access to any other repo with your key.
To solve this, remove the key from repo1’s deploy keys and attach it on your account page instead. This key will now have access to all repos your account has access to.
See Deploy Keys
What are deploy keys?
Deploy keys are ssh keys just like the ones you attach to your account to allow you to push to and pull from your repos.
The only difference is that deploy keys are designed to allow access to a single private repo.
This will allow your staging or production server to pull in from your repo
The other possibility is that somehow your 'origin' remote is incorrect (check what git remote -v returns)

Related

Permission denied to git push as a contributor

Recently I have been added as a contributor to a program allowing me to make some changes but I can't git push my fixed code to the repo.
The error is as follows:
remote: Permission denied to myusername.
fatal: unable to access 'program URL': The requested URL returned error: 403
I can create a pull request to modify the file but my instructor said it would be troublesome if he had to check the request and merge them every time so he added me as a contributor.
I googled my question and some said I need to add my SSH key to my instructor's account, but does it mean I have permissions to all repo of my instructor?
I'm just a beginner in github, many thanks for your help!
You need to have an SSH key for your own account (not your instructor's). If he added you as a contributor and you cloned the repository via SSH (as it seems you did), Github will check your personal SSH key to identify you whenever you try to push.
Just follow these steps to add your SSH key to your account: https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account

Pushing a local repo to multiple github accounts

This one is rather complicated to describe. I have two github accounts, I will refer to them as github A and B.
I had created a local repo X and tried to connect it to a new remote repo I created on github account A. However, my default github login credetials were set for my github account B. I went through this tutorial and was able to add a second key created in my .ssh to allow me access to acct. A at will. This method worked and allowed me to add the new remote repo on github account A to my local repo X. I could then push origin to master just fine.
I then made a clone of the same repo X on github account A and placed it in a new local location (same drive, different folder) which I will refer to as local repo Y. I then tried to push changes to the same remote repo on github A and it denies me saying I'm trying to access using my username for my remote github B account.
I tried re-adding the remote url via the same special .ssh key previously created for repo X and use it for the local repo Y but it says it already exists.
I'm looking for a simple solution here, hopefully one exists. I would appreciate your help on this.
You can test what actual key is used with:
ssh -Tv <yourSSHConfigEntry>
Make sure to use an ssh URL like yourSSHConfigEntry:/ (no need to prefix it with git#: the User should be in your ~/.ssh/config file)
The idea is: your SSH config file should use the right private key, whose public key has been registered to the right GitHub account.
Check the remote URL: git remote -v. If it starts with git#github.com, it won't use the ssh config entry.
Type:
git remote set-url origin <my-github-acct-A>:<user>/<repo>
That will use the SSH config entry, and make sure the User in it is "git".
I'm pretty sure the issues you're running into are a result of managing multiple accounts on the same computer, regardless of the repos being duplicates.
If you haven't already, I'd suggest you take a look at the very detailed answers provided here.
I have been through this trouble many times and have resolved it by setting the ssh config rules or by enforcing the ssh-agent to have the correct ssh key alone.
I have documented the entire process and Freecodecamp published the article.
Here's the link! Hope this will help whenever you come across this use case. :)

SSH access to GitHub repository

I have followed the process described in Multiple GitHub Accounts & SSH Config (stefano's answer) and have set up SSH access to multiple repositories using deploy keys. I've tried that on repositories of a specific GitHub organization and it works fine - I can pull and push changes. I've also tried this on my user area and it still works great.
However, when trying this on repositories in another GitHub organization (e.g. when doing a git push) it fails with the following error
ERROR: Permission to XXXX/YYYY.git denied to deploy key
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
When checking SSH access through ssh -T I get
"Hi XXX/YYYY! You've successfully authenticated, but GitHub does not provide shell access."
which suggests that SSH should be working.
I have gone through the organization settings (main page for GitHub organization > Settings) and they have pretty much identical settings, except from what you would expect to be different e.g. contact email etc.
I was wondering if anyone has any ideas about what could be causing this. Are there any more organization settings somewhere by any chance?
ERROR: Permission to XXXX/YYYY.git denied to deploy key
This looks like you are trying to push using a deploy key. This key is used for deployment and therefore only to read-only access of your repository. Make sure you have the key which is enrolled in your github account, make sure it is used (IdentityFile in ~/.ssh/config) and get rid of the deploy key from the standard location which is picked by default (~/.ssh/id_{rsa,dsa,ecdsa,ed25519}). Note, that if there are more "valid" keys, only the firs succeeds.

Automated build from Github private repositority on Docker Hub doesn't work

I'm trying to create an automated build on Docker Hub from a Github private repository.
I linked my Github account with my Docker Hub account.
I verified that the deploy keys provided by Docker Hub are created in my Github repository
But I still have an error. I'm not sure if it's related to SSH keys or gitmodules.
Here is the log I get (in Build Details tab in my Docker Hub repo) :
Starting to clone
Cloning into 'bsntx4mjvrqncsdvzcn7tqp'...
Warning: Permanently added the RSA host key for IP address 'XXX.XX.XX.XX' to the list of known hosts.
No submodule mapping found in .gitmodules for path 'vendor/bundle/ruby/2.1.0/bundler/gems/logan-3722sdf9a9db5'
please ensure the correct public key is added to the list of trusted keys for this repository and the remote branch exists. (1)
Does anyone has the same error ?
My solution : I have solved my problem by removing the file vendor/bundle/ruby/2.1.0/bundler/gems/logan-3722sdf9a9db5 in my github repo. So the error about the public keys has nothing to do with it.
The issue is not with the key.
I don't know the exact issue. You can use the following command to sort the issue out.
git submodule update --init
The output of the command will be passed to
git rm --cached {{output}}
Push the commit.
I can't comment, so I'm posting this as an "answer" instead (sorry!)
I have the same issue with Bitbucket, it fails to fetch from my submodule which is included in my main repo. I haven't been able to fix this issue yet. I even bough a paid subscription and added an automated build in hub.docker, hoping that would fix it, but nope..
Starting to clone
Cloning into 'bokyrk3hkhspby5smhf6kby'...
Warning: Permanently added the RSA host key for IP address 'xxx.xxx.xxx' to the list of known hosts.
Submodule 'lib/shared' (https://xxx#bitbucket.org/xxx/xxx_sharedlibs.git) registered for path 'lib/shared'
Cloning into 'lib/shared'...
fatal: could not read Password for 'https://xxx#bitbucket.org': No such device or address
Clone of 'https://xxx#bitbucket.org/xxx/xxx_sharedlibs.git' into submodule path 'lib/shared' failed
please ensure the correct public key is added to the list of trusted keys for this repository and the remote branch exists. (1)
Following procedure followed by me made it work:
Added my private key to local ssh through git bash.
Added my public SSH key to github.
This ssh key was already available in my dockerhub.
So, I linked another public dockerhub userid (where automated build was successful) as a collaborator to this private automated build.
For work with private repo, you should add ssh key from Docker Hub (showing on add auto build) to your github ssh keys.
When the automated build fails the orange alert on the top of the build details can be a bit deluding:
Build failed: please ensure the correct public key is added to the
list of trusted keys for this repository and the remote branch exists.
(128)
Even when you have set up you ssh keys this message always displays. You need to look at your Logs at the bottom of the build details to see more information if you know that you have set up your ssh keys for a private repo already.
For example your logs might say:
fatal: no submodule mapping found in .gitmodules for path
'my-app/my-blog'
or maybe it could be
Dockerfile not found at ./my-app/Dockerfile
in your case you had a problem related to having the file vendor/bundle/ruby/2.1.0/bundler/gems/logan-3722sdf9a9db5 in your solution which needed to be removed.

How to create a Gitlab webhook to update a mirror repo on Github?

I would like to create a webhook within Gitlab to automatically update a mirror repository on Github, whenever a push event happens. I've checked this page, but I didn't understand how it is done.
My Gitlab version is 6.5. Here is the configuration page:
What should I put in URL? Where do I need to place the script to update the repository?
You don't need a webhook for that. A regular post-receive hook will work very well.
To create and use such a hook you just have to login on the server where your gitlab is installed and create an ssh key for git user.
sudo -u git ssh-keygen -f /home/git/.ssh/reponame_key
(do not type any passphrase when prompted)
Go to your github account and add the public key (it's been created as /home/git/ssh/reponame_key.pub) to your project as a deploy key.
have a look at https://help.github.com/articles/managing-deploy-keys if you need help with that.
Once that is done, you just have to configure the connection between your git server and github's:
add an alias to git user's ssh configuration (add following lines to /home/git/.ssh/config - create it if it's not present)
Host reponame
IdentityFile /home/git/.ssh/reponame_key
HostName github.com
User git
Now add the new remote (using the alias you just created) to your repository:
cd /home/git/repositories/namespace/reponame.git
git remote add --mirror github reponame:youruser/reponame.git
Now that everything is in place you'll have to create the actual hook:
cd /home/git/repositories/namespace/reponame.git/hooks
echo "exec git push --quiet github &" >> post-receive
chmod 755 post-receive
The lastcommand is very important because git will check if a hook is executable before running it.
That's it!
(Replace reponame, namespace and youruser according to your real accounts and enjoy).
Last note: if you want your name andavatar near commits on github, make sure that the email address you are using on gitlab is one of the addresses inked to your github account as well. You'll see your gitlab username otherwise.
If you aren't hosting your own GitLab, GitLab.com has introduced this feature directly, without any workarounds.
From within a project use the gear icon to select Mirror Repository
Scroll down to Push to a remote repository
Checkmark Remote mirror repository: Automatically update the remote mirror's branches, tags, and commits from this repository every hour.
Enter the repository you want to update; for GitHub you can include your username and password in the URL, like so: https://yourgithubusername:yourgithubpassword#github.com/agaric/guts_discuss_resource.git —as noted in the comments, it is much better securitywise to use your GitHub access token here instead of login credentials; will update the answer when i've tested.
For WebHooks processing I'm using sinatra web server.
require 'sinatra'
post '/pew' do
puts JSON.parse request.body.read
# here can be placed signal code to run commit processing script
end
register webhook for push events(or other) to http://localhost:4567/pew within GitLab
and since this moment on each commit gitlab will be sending commit info to url.