How to connect a project from IDEA to Gitlab - intellij-idea

Is it possible to connect a project from IDEA to Gitlab?
There are no problems with GitHub, you specify a github account, then VCS-> Import into and it creates a project in your account. But with GitLab I don't see such a possibility. Maybe there is some way?
Or just manually throw it in there?

If all you want to do is create a project, that is as simple as pushing the repo. In GitLab, you don't have to create the project in the UI first. You can simply push directly to a project namespace that does not yet exist. The project will be created when you push to it.
Therefore, all you have to do is configure your git remote per usual, then push.
git init
git checkout -b main
echo "# My Project" > README.md
git add README.md
git commit -m "initial commit"
git push --set-upstream git#gitlab.com:namespace/myproject.git main
Then you'll see the message from the remote in the git console log
remote: The private project namespace/myproject was created.
In the JetBrains IDEs, you can simply configure the remote and push.
You only have define the remote ahead of time in the terminal. For example:
git remote add origin git#gitlab.com:namespace/project
Then in the IDE, when you go to push, you'll see the ability to push to the new remote/branch.
Then you'll also note in the git tab console you'll see the message from the remote that the project has been created.

Full integration for GitLab hasn't been implemented yet, but there is a feature request for that:
https://youtrack.jetbrains.com/issue/IDEA-109294
Meanwhile, you can create a repository in GitLab, then press Cmd/Ctrl+K and Click "Commit and push". In Push dialog there will be "Define remote" button - click on it and paste URL to GitLab's repository.
If it's HTTPS then you'll be prompted with username and password - enter them, alternatively you can enter Username and Personal access token (in password field)

Related

How to change the master username at git in WebStorm?

WebStorm tries to push my project to an account that does not exist anymore. How do I change it? I have already added the new account to WebStorm and it still tries pushing to the old account.
You can change it in Settings>Repositories.
Setting>General>Repository name>rename
The entry highlighted on the screenshot is the commit author. This information is written in the commit, and is not related to the account that is used to push the change.
Author is determined by git configuration. You can check and change it using CLI - git config user.name and git config user.email
To change the author of the commit in question you need to re-do the commit.
Make sure git user is correctly set in git config, then undo the commit, and commit changes again.
To push, WebStorm will authenticate using the account configured in Settings | Version Control | GitHub, or according to the ssh config if ssh access is used.

Intellij - Unable to clone the repository "Clone Failed - Unable to access '<<repo url >> ': Recv failure: Connection was reset

I am trying to clone a repository using IntelliJ. I am very new to IntelliJ. I am able to clone the repository using eclipse though.
In eclipse (Git Repositories view), I am asked to provide credentials to access company's GIT Server but not sure where to provide these in Intelli J. I know I can login to GitHub account through IntelliJ but I am trying to access the repo which is in company's GIT server.
Please point out what wrong I am doing and guide me.
In IntelliJ, these are steps I am following.
Go for File -> New -> Project from Version Control
Select Repository URL and enter the values for fields URL and Directory. Click on Clone.
Here's the error snapshot
For future references to anyone having this same problem, copying the code url instead of ssh from github would solve this issue.

Using Gitlab deploy keys with write access

I am currently running CE version 8.17.4 and am attempting to setup a deploy key with write access (as of 8.16) so that my runner instance may commit build artifacts back to the repository. I took the following steps to set this up:
On the runner instance, I generated the ssh keypair with the command: 
sudo ssh-keygen -t rsa -C "label" -b 4096
The generated keypair was saved to /home/gitlab-runner/.ssh/id_rsa and password protected.
Within Gitlab, I created a public deploy key from the admin console and pasted the contents of id_rsa.pub into the appropriate field and verified that the key fingerprints matched. I checked the "Write access allowed" box. 
In the private project that I wished to enable repository access from the runner, I enabled the newly created public deploy key.
This is a LaTeX document respository, so in the .gitlab-ci.yml file, I issue the following script after building the pdf:
after_script:
  - "git commit -am 'autobuild PDF'"
  - "git push origin master"
When the changes were committed, the build ran successfully on the runner up until the git push origin master command, and this error was thrown:
fatal: Authentication failed for 'http://gitlab-ci-token:xxxxxxxxxxxxxxxx#host/project.git/'
Ok. A couple questions:
If the deploy key is just an SSH key, shouldn't it be connecting on the secure port or does this matter? I haven't found much documentation on using this new write-permission deploy key feature, so am I missing something in the steps I took above?
Do I need to include [ci skip] in the commit message to avoid looping CI builds? I saw this concern come up in the original issue tickets for this feature, but did not see whether this step was required or not. 
Thanks for any help!
Jawad's comment worked for me: you need to force SSH. for example
git remote add ssh_remote git#host:user/project.git
git push ssh-remote HEAD:dev
thanks jawad

How to tag a git repo in a bamboo build

I'm trying to tag the git repo of a ruby gem in a Bamboo build. I thought doing something like this in ruby would do the job
`git tag v#{current_version}`
`git push --tags`
But the problem is that the repo does not have the origin. somehow Bamboo is getting rid of the origin
Any clue?
Yes, if you navigate to the job workspace, you will find that Bamboo does not do a straightforward git clone "under the hood", and the the remote is set to an internal file path.
Fortunately, Bamboo does store the original repository URL as ${bamboo.repository.git.repositoryUrl}, so all you need to do is set a remote pointing back at the original and push to there. This is what I've been using with both basic Git repositories and Stash, creating a tag based on the build number.
git tag -f -a ${bamboo.buildNumber} -m "${bamboo.planName} build number ${bamboo.buildNumber} passed automated acceptance testing." ${bamboo.planRepository.revision}
git remote add central ${bamboo.planRepository.repositoryUrl}
git push central ${bamboo.buildNumber}
git ls-remote --exit-code --tags central ${bamboo.buildNumber}
The final line is simply to cause the task to fail if the newly created tag cannot be read back.
EDIT: Do not be tempted to use the variable ${bamboo.repository.git.repositoryUrl}, as this will not necessarily point to the repo checked out in your job.
Also bear in mind that if you're checking out from multiple sources, ${bamboo.planRepository.repositoryUrl} points to the first repo in your "Source Code Checkout" task. The more specific URLs are referenced via:
${bamboo.planRepository.1.repositoryUrl}
${bamboo.planRepository.2.repositoryUrl}
...
and so on.
I know this is an old thread, however, I thought of adding this info.
From Bamboo version 6.7 onwards, it has the Git repository tagging feature Repository Tag.
You can add a repository tagging task to the job and the Bamboo variable as tag name.
You must have Bamboo-Bitbucket integrated via the application link.
It seems that after a checkout by the bamboo agent, the remote repository url for origin is set as file://nothing
[remote "origin"]
url = file://nothing
fetch = +refs/heads/*:refs/remotes/origin/*
That's why we can either update the url using git remote set-url or in my case I just created a new alias so it does not break the existing behavior. There must be a good reason why it is set this way.
[remote "build-origin"]
url = <remote url>
fetch = +refs/heads/*:refs/remotes/build-origin/*
I also noticed that using ${bamboo.planRepository.<position>.repositoryUrl} did not work for me since it was defined in my plan as https. Switching to ssh worked.

Unable to use egit to clone a repository with ssh

I try to clone a GIT repository with EGit using SSH. I can log on to the machine, see the available branches and choose where to put everything locally. Then when I proceed to actually do the cloning, I get an Eclipse "Problem Occured" box stating:
"Cloning from ssh://[my user name]#[my address] has encountered a problem. ssh://[my user name]#[my address]: Password:". The details for the problem only list "ssh://[my user name]#[my address]: Password:" twice.
The only possible reason I can think of, might be that on the remote compute only Git 1.6.0.x is installed - and I don't have the rights to update it.
Can you clone the repository using native git? If you can do that, just clone it using native git and then import the project into eclipse using:
File -> Import -> Projects from Git -> Local
If your eclipse runs on Windows, you will need a linux machine (virtual machine will do) and clone the repo into a NTFS or Fat32 formatted storage. Then you will be able to copy the cloned repo into your git folder on the windows machine.