0

I have git bash installed on Visual Studio Code Windows. This is what I have so far:

git push
fatal: No configured push destination.

Then I set remote origin to https not ssh because I have a Large file and LFS doesn't work well with SSH (well at least that's what it said in stackoverflow somewhere, I forget)

$ git init
Reinitialized existing Git repository in C:/xampp7.2/htdocs/folder2-temp/.git/

$ git branch -M main

$ git remote add origin https://github.com/mygithubid/myrepository.git

$ git add .

$ git commit
On branch main
nothing to commit, working tree clean

$ git push
fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin main

$ git push --set-upstream origin main
Enter passphrase for key '/c/Users/guestaccount/.ssh/id_rsa': 
Uploading LFS objects:   0% (0/1), 0 B | 0 B/s, done.
batch request: git@github.com: Permission denied (publickey).: exit status 255
error: failed to push some refs to 'ssh://github.com/mygithubid/myrepository.git'

So as suggested on stackoverflow I tried this:

$ git remote -v
origin  ssh://git@github.com/mygithubid/myrepository.git (fetch)
origin  ssh://git@github.com/mygithubid/myrepository.git(push)

Ok Cool. Need to reset that to https://

$ git remote set-url origin https://github.com/mygithubid/myrepository.git

Ok let's see if SSH was reset to HTTPS

$ git remote -v
origin  ssh://git@github.com/mygithubid/myrepository.git (fetch)
origin  ssh://git@github.com/mygithubid/myrepository.git (push)

Bite me!

Ok someone please help me reset github to https from SSH I am sincerely stuck :D

d7l2k4
  • 175
  • 1
  • 2
  • 14
  • 1
    Why not use the instructions for cloning your repo with HTTPS? – astrochun Apr 24 '21 at 20:06
  • 1
    Most of your commands did nothing. Your `git init` was pointless. – matt Apr 24 '21 at 20:26
  • Anyone? Also should I git clone using https and start pushing again? – d7l2k4 Apr 24 '21 at 23:01
  • 2
    It is curious that `git remote set-url origin` had no apparent effect. It's just a string; you should be able to change it trivially. Even `git remote set-url origin cowabunga` should work! Maybe you are giving these commands from different places, i.e. the current directory is not what you think it is? But it's hard to say, without more info. – matt Apr 24 '21 at 23:23
  • 2
    Git-LFS doesn't interact one way or another with ssh vs https push operations. All Git-LFS does is *replace* large files with indirections, so that the large files aren't stored in *Git* at all. (Your large files are stored somewhere else. Git-LFS notices during `git checkout` that the file has been replaced with the indirection, and goes to the large-file-server to fetch the file. This ties you to Git-LFS forever, but if you have to do that, you're kind of stuck with that.) – torek Apr 25 '21 at 00:46
  • 1
    Looking over your settings, I was surprised you have `ssh://`. My SSH remotes is just `git@github.com...` – astrochun Apr 25 '21 at 03:07

1 Answers1

1

When you open the C:/xampp7.2/htdocs/folder2-temp/.git/ folder, you should see a bunch of files in this folder, and the file of interest in this case is the config file.

When you open the config file, what do you see? There should be something like this:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = git@github.com/mygithubid/myrepository.git
    fetch = +refs/heads/*:refs/remotes/origin/*

You might not have the same settings under the [core] section, but the [remote "origin"] section should be similar. If you want to change the git repo to use https instead of ssh, try changing

    url = git@github.com:mygithubid/myrepository.git

to

    url = https://github.com/mygithubid/myrepository.git

in this config file directly. This should fix the problem you have, so when you run git remote -v, you should now see

$ git remote -v
origin  https://github.com/mygithubid/myrepository.git (fetch)
origin  https://github.com/mygithubid/myrepository.git (push)

EDIT: As discussed in the comments section, modifying files within your .git directory is generally not best practice since changing something that you're not supposed to change in the .git directory might corrupt your git workflow for this repo. However, the problem is this case seems to be that the git commands aren't modifying the .git/config file as they should be, so modifying the url = line under the [remote "origin"] would be a workaround to get git to communicate with the remote server.

NOTE that the changes I suggested above in my original answer will not corrupt your local git repo, but just keep in mind that changing/deleting any of the other folders or files inside the .git directory might corrupt it if you do make a bad change.

This workaround I suggested will probably get your local repo communicating with your remote repo, but you should probably take a look at your git bash installation for Windows and check the options you selected since it looks like some of your git commands aren't working as they should be. If the problem isn't with git bash, it might be some other settings the installer configured for git when you were installing git - unfortunately, debugging this is tricky without a comprehensive understanding of the git configuration, so you might need to do some digging on your own here :)

slow-but-steady
  • 961
  • 9
  • 15
  • 1
    The git commands you run essentially modify the config file for you so you don't need to manually modify them directly (this is a good thing since if you change something within the `.git` directory that you **shouldn't** have changed, your whole git process might be corrupted), but modifying the parameters within the config file also does the same thing. I also tested this process on a git folder I have locally and this did the trick :) To make sure you don't mess things up, you could also copy what you have in the `config` file into another file as a backup, but shouldn't be a problem! – slow-but-steady Apr 25 '21 at 00:59
  • 1
    I guess what I'm saying is, if you think something is "off" with the `remote.origin.url` setting, the way to fix it is with `git config` and the `remote.origin.url` setting. Editing the config file directly is a good way to lame your Git accidentally. – matt Apr 25 '21 at 01:04
  • 1
    Ah yes, I agree! The proper way to do this should be with `git remote set-url origin git@github.com:mygithubid/myrepository.git` if you want to use `ssh`, or `git remote set-url origin https://github.com/mygithubid/myrepository.git` to use `https`. However, it looks like OP tried that and it didn't work for them, so this is a potential workaround. – slow-but-steady Apr 25 '21 at 01:08
  • 3
    But we have the OP's word that `git remote set-url origin` didn't have any effect. Are we any closer to knowing how that is possible? – matt Apr 25 '21 at 01:09
  • 1
    I just tried the `git remote set-url origin` command with both the `ssh` url AND the `https` url, and `git remote -v` correctly showed the changes for me, so there might be something wrong with OP's git setup as it is. When I was running these commands, I also had the `config` file open to the side and the `git remote set-url origin` command changed the lines I said to directly modify in my answer above, so my guess is OP's git commands aren't updating the lines in the `config` file as the commands should be. I think you're right though, we don't know for sure what's going on with OP's git atm – slow-but-steady Apr 25 '21 at 01:11
  • Thank you for all your help. This is what I see in the config file. Weird, huh? I am having a bit of a problem uploading a single image. It just sticks there. [core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true [credential] helper = store [lfs "https://github.com/ryanmoutsourcing/restart.git/info/lfs"] locksverify = false [remote "origin"] url = https://github.com/ryanmoutsourcing/restart.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "main"] remote = origin merge = refs/heads/main – d7l2k4 Apr 25 '21 at 02:16
  • 1
    Hmm, so based on this, I think the problem might be that your url is missing the `https://` prefix - try adding `https://` to your url so that your url line looks like `url = https://github.com/ryanmoutsourcing/restart.git` – slow-but-steady Apr 25 '21 at 02:33
  • I put it but it doesn't seem like I can upload any images to github, regardless of size. It keeps giving the same error with LFS. – d7l2k4 Apr 25 '21 at 05:02
  • 1
    Thank you for all your time. I have learned something new, even though I now realize that the problem may be that the LFS system is not working. I guess I should try to disable LFS or something. I have given everyone upvotes and credited the person who answered. – d7l2k4 Apr 25 '21 at 21:48