How to disable SSH from GitHub repository and using only HTTPS for push and fetch? - android-studio

I have created repository on my GitHub account and successfully added my android studio project to it last week
I could push and pull with no issue but suddenly GitHub doesn't allow me to clone repository URL from android studio or push or pull the project
After hours of investigation I understood that a public key for SSH is needed
I even created that with git command lines and copied it in GitHub settings, but still have same problem.
1- Why I could work with GitHub but now I can't?
2- How to disable SSH from GitHub repository and using only HTTPS for push and fetch?
3- What is the best solution for this? I just want to push / pull the project.
** New explanation **
I did what #VonC said but no change on URLs :
By the way, I use Android Studio
I did push then get this error :

Finally I found the solution by #VonC help
I created ssh public key in my bin terminal in windows 10.
I added that to my github acount/settings.
( just need to be checked) I get authorized in bin terminal (windows):
MINGW64 /bin $ ssh -T git#github.com
Enter passphrase for key : XXX
... Hi tahadev! You've successfully
authenticated
Then
I did this command in Android Studio terminal :
"git remote set-url origin git#github.com:tahadev/Native_Form_Android.git"
Then
(By the way it is weird why it shows HTTPS url when setting for SSH)
"git remote -v"
origin https://github.com/tahadev/Native_Form_Android.git (fetch)
origin https://github.com/tahadev/Native_Form_Android.git (push)
Then I did PULL first then PUSH, in some back/force :) I finally could be able to reach my code in git from Android Studio
Thx #VonC
Android Studio terminal code and bin terminal

I find strange that the first push error message mentions "Git#github.com": only git#github.com could work, not Git.
But in any case, if you want to experiment with HTTPS without changing anything, type anywhere:
git config --global url."https://github.com/".insteadOf git#github.com:
Then check again how a push works in VSCode.
To revert:
git config --global --unset-all url.https://github.com/.insteadof
That insteadOf setting would not change a git remote -v output (still SSH there)
If would simply ensure to use an HTTPS URL when doing a git push.

Related

Android Studio, Github login problem incorrect credentials

I've started working with Android Studio and I found a problem when trying to connect to Github. I've tried restarting Android Studio and even creating a new project, but I am not able to login.
I installed Git and it´s working in the local repository.
The problems are:
Incorrect credentials
Request response: 401 unauthorized
You can use the Project from Version Control, it has git.
What I did was I logged in through a token, it also tells you what needs to be added to the token and that worked for me.
You can create the token here:
https://github.com/settings/tokens
Note: I found this solution on: Can't log in to GitHub on Android Studio.
Such solution worked perfect for me!
On GitHub:
Log in -> Click on your avatar in the top right hand corner
Choose Settings -> Developer settings -> Personal access tokens
Click on the "Generate new token" button
Add a note if you want (in my case was mandatory), like "Android Studio"
Select repo(all), read:org (under admin:org), gist
Click on the "Generate token" button
Copy the token
On Android Studio:
Go to File -> Settings -> Version Control -> GitHub
Add an account (plus button on the right side, choose "log in with token")
Click the "Use Token" hyperlink, like in your screenshot
Paste your token, click login, click ok
I got the issue solved by generating a token from https://github.com/settings/tokens and using it to add account option on Android Studio>File>settings>GitHub
you can install git in your operation system and use command for add your android project to github repository.
1- you should install git bash
2- open git bash in your project directory and initial it as a git repository
git init -b main
3- add your project to the local repository
git add .
4- commit your file to the local git repository
git commit -m "First commit"
5- Create a branch, usually called a 'main' or 'master'
git branch -M main
6- define remote git url
git remote add origin remote repository URL
7- finally, you should push all your project into remote git repository
git push -u origin main
Couple of issues can be there to block you from accessing your github repo and throwing 403 error. Hence please go step by step.
Step-1 : Local git is corrupted or not working
git branch -r [If it gives result you are good]
git ls-remote --heads <remot_git_location>
if one of the above is working then your local git is good. If not use
git config --global --unset credential.helper
Step-2 : From your IDE (IntelliJ or Android Studio etc) see git is configured and test it.
Go to Default Settings-->GitHub and Your host should be "https://github.com"
Get your Github personal token. Login to your github account from browser. Settings -> Developer settings -> Personal access tokens.
o Select all “repo”, gist and “read.org” in your scope.
o Create the token
Last step: If still not working, Go to VCS--> GIT --> Remotes --> Change the repo to include token explicitly
https://user_name:<your_TOKEN>#github.com/reponame.git
Paste the token in your IDE and test the connection.
If your problem still persists then check if there is network issue.
Updating to AndroidStudio 4.1.1 allowed me to access with my credentials without having to generate a token.
You have to check all required settings (see image GitHub settings required) at your GitHub account at https://github.com/settings/tokens/, and then you have to update the token (You must regenerate your token if you havent copied yet).... Then you can insert your credentials again in Android Studio and... ¡ready!

How can I determine the URL my git repo is located?

I am to work on a project and I have initialized a git repo on a server. Let's suppose the URL of the server is
foo.bar
and the repo is at
/var/www/vhosts/foo.bar/httpdocs
I have created a git repo by running
git init
and then I created a .gitignore file, added whatever needed to be added, committed and from my local computer, which has ssh access to the server I have attempted to clone the repo, but I do not seem to find the correct URL or something is not set for the repo. I tried something like:
git clone https://foo.bar/httpdocs/.git
The error was
fatal: repository 'https://foo.bar/httpdocs/.git' not found
I have tried with various pathes.
FYI: I have worked with git a lot in the past, but I have never set up a repository on a server, I have always received the path of repos created by someone else. Now I have created the repo, but I cannot seem to find out what the correct URL is. I have searched a lot to find this out, but unfortunately I did not find anything which would help me. Any ideas?
If you're trying to communicate via SSH, you need the SSH link, not the HTTP(S) link:
git clone <user>#foo.bar:/var/www/vhost/foo.bar/httpdocs/.git
You need git and sshd (or openssh-server) installed on the remote server, and add your SSH key to the server, under the correct user (with ssh-copy-id, of course).
This is pramar error.
The error is in line:
cit clone https://foo.bar/httpdocs/.git
you can try:
git clone https://foo.bar/httpdocs/.git
good luck.

How do I clone a git repository located on my Mac connected to the internet?

I have an up-to-date git repo that I started on my MacBook. The project that I am working on is required to work on my university's Linux workstations that I can login to remotely via SSH. I've cded to the directory that I want to clone to on the workstation. I just have no idea how to get the SSH address for the repo on my MacBook when its connected to the internet. Also, how would this stay consistent considering I get a different IP every time I reconnect or go somewhere? Is what I'm doing even possible or a good idea?
One simple solution is to create an empty repository using a free github.com or bitbucket.org account. Using github for this example, you would then have a URL for the repo such as:
https://github.com/username/repo-name.git
Then, simply push the contents of your local repo up to the newly created online repo like so:
$ git remote add origin https://github.com/<username>/repo-name.git
$ git add --all
$ git commit -m 'initial commit'
$ git push -u origin master

Eclipse egit Error when trying to fetch or push

I'd cloned some respositories from github to my local machine (linux x86 32 bit kubuntu 12.04).
In general, I do clone from command line and then connect to eclipse using git perspective and
"add existing local git repository to this view".
After that, I'm able to import projects (from working directory), performing commit and something else.
But when I try to fetch or push against the remote repository, I got some different error messages.
When trying to fetch, I got the error message: Invalid remote: origin
And when I try to push, I got something like: https://github.com/Joe-Merten/Playground: https://github.com/Joe-Merten/Playground/info/refs?service=git-receive-pack not found
Fetch and push via egit definitively has worked until about 10 days ago.
Fetch and push from linux command line is still working without problems.
When trying to clone using eclipse egit, I also got an error like: https://github.com/…/refs?service=git-receive-pack not found
I tried that out with eclipse 4.2 SR2 (Juno) and 4.3 SR2 (Kepler) and 4.4-M6 (Luna Prerelease) on some different linux machines.
Any suggestions?
This could be a credential issue, as mentioned in "An internal Exception occurred during push: cannot store objects":
I just reconfigured the eclipse and added my github account information and store it.
Then it worked.
Team->Remote->Configure push to upstream->URI, Change->Add authentication details
The other classic issue is a capitalization problem in the url ("git-upload-pack not found"), but if it is working from the command line, this shouldn't be the case here.
Ok, it seems that I'd ran into the .git suffix issue.
Solution: I have to add .git to the URI.
Like Lars Vogel wrote in this nice article here: Copy the URL from Github and …,
I'd just used that URI without adding the .git suffix.
So, I'd performed clone like:
$ git clone https://github.com/Joe-Merten/Playground
and that configures my clone to have the following remotes:
$ git --git-dir=Playground/.git remote -v
origin https://github.com/Joe-Merten/Playground (fetch)
origin https://github.com/Joe-Merten/Playground (push)
This way causes the described error messages.
But when I add that .git suffix to the URI:
$ git clone https://github.com/Joe-Merten/Playground.git
my remotes will also have .git suffix
$ git --git-dir=Playground/.git remote -v
origin https://github.com/Joe-Merten/Playground.git (fetch)
origin https://github.com/Joe-Merten/Playground.git (push)
Using this way, egit works as expected.
Looks like that (with or without .git suffix) don't matters as long as I using git from command line.
But when using egit as frontend, this is obviously important.
(Hmm, wondering why that was not a problem until about middle of March 2014.)

Git - Syncing a Github repo with a local one?

First off, forgive me if this is a duplicate question. I don't know anything but the basic terminology, and it's difficult to find an answer just using laymen's terms.
I made a project, and I made a repository on Github. I've been able to work with that and upload stuff to it for some time, on Windows. The Github Windows application is nice, but I wish there was a GUI for the Linux git.
I want to be able to download the source for this project, and be able to edit it on my Linux machine, and be able to do git commit -m 'durrhurr' and have it upload it to the master repository.
Forgive me if you've already done most of this:
The first step is to set up your ssh keys if you are trying to go through ssh, if you are going through https you can skip this step. Detailed instructions are provided at https://help.github.com/articles/generating-ssh-keys
The next step is to make a local clone of the repository. Using the command line it will be git clone <url> The url you should be able to find on your github page.
After that you should be able to commit and push over the command line using git commit -am "commit message" and git push
You can use SmartGit for a GUI for git on Linux: http://www.syntevo.com/smartgit/index.html
But learning git first on the command line is generally a good idea:
Below are some basic examples assuming you are only working from the master branch:
Example for starting a local repo based on what you have from github:
git clone https://github.com/sampson-chen/sack.git
To see the status of the repo, do:
git status
Example for syncing your local repo to more recent changes on github:
git pull
Example for adding new or modified files to a "stage" for commit
git add /path/file1 /path/file2
Think of the stage as the files that you explicitly tell git to keep track of for revision control. git will see the all the files in the repo (and changes to tracked files), but it will only do work on the files that you add to a stage to be committed.
Example for committing the files in your "stage"
git commit
Example for pushing your local repo (whatever you have committed to your local repo) to github
git push
What you need to do is clone your git repository. From terminal cd to the directory you want the project in and do
git clone https://github.com/[username]/[repository].git
Remember not to use sudo as you will mess up the remote permissions.
You then need to commit any changes locally, i.e your git commit -m and then you can do.
git push
This will update the remote repository.
Lastly if you need to update your local project cd to the required directory and then:
git pull
To start working on the project in linux, clone the repo to linux machine. Add the ssh public key to github. Add your username and email to git-config.
For GUI you can use gitg.
PS : Get used to git cli, It is worth to spend time on it.

Resources