How to add Gitlab-token to sourcetree? - gitlab

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.

Related

Which git hook could i use for a specific scenario

I have a git remote where all users pushes to. Now i want another remote in this remote and it should automatic pushes if it receives commits.
Is that feasible, or do I have to do a git push -u origin --all with cron?
Going by the git documentation, you can add another remote url to the existing remote
git remote set-url --add --push origin <remote-url>
git remote -v should now return two urls configured for push.

Gitlab pushing first project failed due to could not read from remote repository

I was new to Gitlab was trying to push my project from local machine to Gitlab.
Have done the SSH key and followed the instructions at Gitlab. Done the Git global setup. Was trying to add an existing folder , so i followed the instructions listed
cd existing_folder
git init
git remote add origin https://gitlab.com/sss/testnode.git
git add .
git commit -m "Initial commit"
git push -u origin master
but failed at the last step at the git push. The error message was
Tried adding the remote origin, but it was told it already exists. So not sure where it went wrong. Please help, much appreciated :)
Have done the SSH key
The problem is that you have defined your origin as HTTPS, not SSH.
Try:
git remote set-url origin git#gitlab.com:sss/testnode.git
That will override origin URL.
Independently, make sure your SSH key does work and allows GitLab to authenticate you as your GitLab account with:
ssh -T git#gitlab.com
Check out your credentials, if they are invalid, it wont give u to upload changes.
For Windows check this: https://www.digitalcitizen.life/credential-manager-where-windows-stores-passwords-other-login-details
For Linux check this: https://askubuntu.com/questions/30907/password-management-applications (if you do not know how to change credentials via terminal)

Folder's content are empty after pushing into bitbucket

I wanted to push folders from my local repositories into bit bucket. Somehow I was unable to do that.
I got the solution somewhere to use
$ git push -f origin master
which resolved the issue but erased all lines of code.
This is my very first use of bit bucket. How to get all content back?
Now, I deleted previous repository and created the new one. Typed below but getting error
$ git remote add origin
https://PoojaThapa#bitbucket.org/PoojaThapa/git-poojatest.git
fatal: remote origin already exists.
$ git push origin
fatal: HttpRequestException encountered.
An error occurred while sending the request.
remote: Not Found
fatal: repository 'https://PoojaThapa#bitbucket.org/PoojaThapa/git-
test.git/' not found
please suggest.
Assuming you have a repository in your current directory you can add a remote with any name using:
git remote add <remote-name> <url>
You are getting an error with your first command because a remote already exists called origin.
Try git remote -v to see which remotes you have already got defined.
In your case I think you want to create a new remote (with a different name, for example bitbucket), so
git remote add bitbucket https://PoojaThapa#bitbucket.org/PoojaThapa/git-poojatest.git
Verify that the remote was created correctly using git remote -v, then you can push to the new remote using <remote-name>/<branch>:
git push bitbucket/master
"repository not found" implies that the origin URL is incorrect. List your current remotes with git remote -v, and double-check that you have the correct URL(s) listed. (You should be able to go to the URL in your browser.)
If something is incorrect, you can fix it with git remote set-url origin correct-url-goes-here.

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

Resources