'git remote' displays different url than set in .git/config - linux

Yesterday started having weird issues with my github repos, when was suddenly prompted for user & passwd for push. Git is set up using ssh, and no changes have been made in months.
$ git remote -v
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)
$ cat .git/config
/-/
[remote "origin"]
url = git#github.com:user/repo.git
/-/
$ git config remote.origin.url
git#github.com:user/repo.git
Re-setting via remote set-url doesn't change anything either.
No issues with bitbucket repos. Has there been some change I've missed?

My gitconfig includes a config from one of the projects I'm currently working on. A new property was introduced I wasn't aware of:
[url "https://github.com/"]
insteadOf = "git://github.com/"
Case closed.

Related

How to add Gitlab-token to sourcetree?

I try to commit a file to a gitlab repo, but I receive
git -c diff.mnemonicprefix=false -c core.quotepath=false
--no-optional-locks push -v --tags origin main:main remote: You are not allowed to push code to this project. fatal: unable to access
'https://gitlab.server.com/Edna/myproject.git/': The requested URL
returned error: 403 Pushing to
https://gitlab.server.com/Edna/myproject.git Mit Fehlern
abgeschlossen, siehe oben.
Therefore, I got a personal access token from my gitlab operator like:
abcde-aC5unFT3ELQT-VMZKSpV
How do I use this PAT? How to enable this in sourcetree git desktop tool?
Your local repository is configured to use HTTPS instead of git over ssh. The output of git remote -v should verify this. You will see something similar to:
origin https://gitlab.server.com/Edna/myproject.git (fetch)
origin https://gitlab.server.com/Edna/myproject.git (push)
Follow the instructions to create and add your SSH key to your GitLab account.
Then, use a SSH remote repository for origin.
$ git remote rename origin https-origin
$ git remote add origin git#gitlab.server.com:Edna/myproject.git
Then, try your git command.

How to set a git repository's remote url without updating the local repository it's cloned from?

There is no remote repository for this project yet but it has a remote set in its config and someone did that for some reason so I won't change it. The original repository is in /home/me/repo1/.git and I ran git clone /home/me/repo1/.git while in /home/me/repo2 so now it's cloned in /repo2
When I go into the cloned repo and run git remote set-url origin http://example.com/asdf/.git both repositories config's get updated.
I can't fork the repo because I don't have admin access and no access to gh cli or similar tools. Is there a workaround to only update the second repository?
Cannot simulate the issue here, and it makes sense, since the remote tracking configuration is on a per repository basis, could you please check if the performed steps resemble the steps provided below? The intent of the pwd commands is to demonstrate the current folder in which the subsequent commands are executed.
Create repo1
$ pwd
/home/user/
$ mkdir repo1
$ cd repo1
$ git init .
Initialized empty Git repository in /home/daniel/Temporary/repo1/.git/
$ git remote add origin http://url.com/repo1.git
Create repo2
$ pwd
/home/user/
$ mkdir repo2
$ cd repo2
$ git clone ../repo1/.git/
Cloning into 'repo1'...
warning: You appear to have cloned an empty repository.
done.
Set remote url for cloned repository
$ pwd
/home/user/repo2/repo1
$ git remote set-url origin http://url.com/repo2.git
Retrieve the remote urls
$ pwd
/home/user/repo1
$ git remote -v
origin http://url.com/repo1.git (fetch)
origin http://url.com/repo1.git (push)
-----
$ pwd
/home/user/repo2/repo1
$ git remote -v
origin http://url.com/repo2.git (fetch)
origin http://url.com/repo2.git (push)

Cannot push to my github private repository

As I'm learning git, I have set up a private repository on GitHub. I have created ssh key and store it to my GitHub account and edited .ssh/config file on my local Linux machine:
## github
Host github.com
User git
HostName github.com
IdentityFile ~/.ssh/github.key
I can successfully connect to my GitHub account:
$ ssh -T github
Hi <UserName>! You've successfully authenticated, but GitHub does not provide shell access.
I have initialized a git repository on my local machine, set up user and added a remote repository:
$ git init
$ git config user.name "UserName"
$ git config user.email "UserEmail"
$ git remote add origin ssh://github:<UserName?/<repositoryName>.git
I have created a README.md file, added it to git and commited it:
$ git add README.md
$ git commit -m "First commit."
Now everytime I try to push, I get this error:
$ git push origin master
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Cloning the repository works, however that is the only thing I can do.
Why can't I push to my private repository? What am I doing wrong?
Try instead the scp syntax, to make sure your ~/.ssh/config file is used:
git remote set-url origin github:<username>/<repo>
Then try and push again.
Git itself uses an OpenSSH version (at least the one packages with Git for Windows)
> ssh -V
OpenSSH_7.5p1, OpenSSL 1.0.2k 26 Jan 2017
As explained in "Why doesn't the ssh command follow RFC on URI?", there is a difference between:
ssh://[user#]host.xz[:port]/path/to/repo.git
vs.
user#host.xz:/path/to/repo.git
Only the latter syntax user#host.xz: uses the ssh config file.
When SSH was originally developed, it was developed as a more secure, drop-in replacement for the earlier RSH/rlogin suite of tools.
See "History of the SSH protocol".
OpenSSH (1999) predates URI (finalized in RFC 3986, published in January 2005)
If the host portion was allowed to be on the form host:port, this would create a potential ambiguity: does jdoe#host.example.com:2222 refer to ~jdoe/2222 on host.example.com when connecting on the standard port, or does it refer to no file at all (or worse, ~jdoe) on host.example.com when connecting over port 2222?

Bitbucket git issue on Linux

I am very new to bitbucket and linux. I am trying to upload files from my local to bitbucket. I tried the following command:
git commit -m 'commit to master'
git push -u origin 'master'
Then I got an error like
fatal: 'origin' 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.
Then I tried
git remote add origin ssh://mjsofttechindia#bitbucket.org:mjsofttechindia/project.git
git push origin master
Then I got an error like
ssh: Could not resolve hostname
bitbucket.org:yourname: Name or service not known fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
Please help. I don't know if this is correct or not. Please help me.
Change remote url to
ssh://mjsofttechindia#bitbucket.org/mjsofttechindia/project.git
git remote set-url origin ssh://mjsofttechindia#bitbucket.org/mjsofttechindia/project.git
Then you have to configure your name and email address (the one that you created your Bitbucket account with) in your local repository
git config user.name "Your Name"
git config user.email "you#email.com"
Then do a push again
git push -u origin master

How correctly set the remote on a local repository to my centralized repository on a server?

I have created a central repository on a Linux server following this tutorial:
http://rypress.com/tutorials/git/centralized-workflows
So basically I actually have this folder:
MyServer#MyUser:~/repositories/backend-central-repo.git$
on my server that represent my remote GIT repository.
I am connecting to this server via SSH using an address like: MyServer.cloudapp.net, the username MyUser and the related password.
Now on my local machine I have a local GIT repository like:
Andrea#Andrea-PC MINGW64 ~/Documents/TESTREPO (master)
In this repository I have committed a test.txt file, infact I have this commit:
$ git log
commit a11633549763c4cc905a721932c4c6bdc1a1091c
Author: AndreaNobili <nobili.andrea#gmail.com>
Date: Tue Oct 4 20:17:35 2016 +0200
test
Then, on my local repository I have added the remote repository as origin, doing:
$ git remote add origin MyServer.cloudapp.net/repositories/backend-central-re
po.git$
Then I try to do:
Andrea#Andrea-PC MINGW64 ~/Documents/TESTREPO (master)
$ git remote -v
origin MyServer.cloudapp.net/repositories/backend-central-repo.git$ (fetch)
origin MyServer.cloudapp.net/repositories/backend-central-repo.git$ (push)
What it means? That it work fine?
"doesn't not appear to be a git repository
The ssh url for your repo should be
MyUser#MyServer.cloudapp.net:/home/MyUser/repositories/backend-central-repo.git
Try in your local repo:
git remote set-url origin MyUser#MyServer.cloudapp.net:/home/MyUser/repositories/backend-central-repo.git
Then, if your remote repo is empty, you can push your local repo to it:
git push -u origin master

Resources