Jenkins pipeline "git push" fails on a Windows build node? - jenkins-pipeline

I wrote a simple pipeline to test for Git access
node("windows-build-node") {
dir(env.WORKSPACE) {
stage("clone") {
sh "whoami"
git url: "git#bitbucket.org:company/someRepo.git",
branch: "development",
credentialsId: "bb-ssh"
}
stage("Create and push branch") {
sh """
git checkout development
git checkout -b feature/test-branch-access
git push origin feature/test-branch-access
"""
}
stage("Test delete") {
sh" git push origin feature/test-branch-access --delete"
}
}
}
and I get
17:34:27 + whoami
17:34:27 SYSTEM
...
17:34:33 + git push origin feature/test-branch-access
17:34:33 Host key verification failed.
17:34:33 fatal: Could not read from remote repository.
17:34:33
17:34:33 Please make sure you have the correct access rights
17:34:33 and the repository exists.
Where is the known_hosts file in Windows so I can add the host key for our Bitbucket server?

Related

Git push error - failed to push some refs to <path>

I am trying to upload my code onto a repository I created on github but I get an error.
Assuming the URL of the repository is https://github.com/a, how do I go about uploading my code to my remote repository?
I tried the following commands on git bash after navigating INSIDE the folder I want to upload -
git init
(output - Reinitializing existing Git repository in C://(path)/.git/
git add.
(blank output)
git commit -m "Initial commit"
(output- On branch main. nothing to commit, working tree clean)
git remote add origin https://github.com/(path).git
(output - error: remote origin already exists)
git push origin master
(output - error:src refspec master does not match any
error failed to push some refs to https://github.com/(path).git)
Why is this happening and what could I do to push my code to my remote git repo? (I want to learn how to use git via cmd)
Thanks for reading my query!
note that you already have an remote repository configured as origin you must remove this configuration or rename then add the correctly repo.
the git command to remove remotes repositories by name is git remote remove ${repo_name}, in your case:
git remote remove origin
the git command to rename remotes repositories is:
git remote rename ${old_repo_name} ${new_repo_name}
then you can add an new remote with the name origin
git remote add origin https://github.com/(path).git
you can assume that the git command git remote add origin https://github.com/(path).git says to git configure an new remote repository into the current local repository, this remote config will "point" to the <URL> and the "alias" of this <URL> will be "origin" (or the name you specify between add and <URL>).
in this case <URL>=https://github.com/(path).git
With this you can have various remotes and specify then when you execute git push ${repo_name}
You can set an "default" upstream for git pull/status with git push -u ${repo_name}
You wrote:
git commit -m "Initial commit"
(output- On branch main. nothing to commit, working tree clean)
git push origin master
(output - error:src refspec master does not match any
Your init created a branch called main but you tried to push master, which doesn't exist. Try pushing main instead.

Automatically copy correct CLI command to clipboard after failure

Suppose I run:
git push
And I get the error message:
fatal: The current branch cdt-rd has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin cdt-rd
Is there a way to conjigger my git or bash so that it automatically copies the correct command (git push --set-upstream origin cdt-rd) to my clipboard?
Would probably be easier to create a smart alias, I use this one:
git config --global alias.pto '!bash -c "git push --set-upstream ${1-origin} $(git symbolic-ref --short HEAD)" -'
Pushes to the origin by default git pto or to another remote git pto remote
It automatically resolves the current branch name, then pushes the branch to the remote and sets the upstream. Also works if you use this command instead of push if the upstream is already set.
git config --global push.default current
You should only have to do this once. Then,
git push

Git Bash Fatal:Could not read from remote repository

So I have a git repo set up on a linux machine and I typed
git remote add test git#*****.com:/opt/git/project.git
and then I did
git init
git add *
git commit -m 'Blah blah'
When I go to do
git push remotename
I get fatal:Could not read from remote repository.
I know it is a problem on my side, because my friend can on his arch linux machine. I have private ssh keys in a different folder then my git bash and then I have public keys in the git user home folder all set up. I don't know if I need to set up SSH keys somehow with git bash or something.
You need to add the upstream repo as a remote
git remote add remotename git#*****.com:/opt/git/project.git
And now do a push
git push remotename
PS : The step where you ran git add git#*****.com:/opt/git/project.git was meaningless, and should have thrown you an error ideally.

How to do push for new repository?

I created new repository (git#github.com:derkode/ForvoClient.git) and did SSH Key, then:
git config --global user.email "my_email#mail.com"
git config --global user.name "my_nickname"
git config --global push.default simple
git init
git add *
git commit -m "First commit"
git remote add origin git#github.com:derkode/ForvoClient.git
But after: git push -u origin master
! [rejected] master -> master (non-fast-forward) error: failed
to push some refs to 'git#github.com:derkode/ForvoClient.git' hint:
Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git
pull') hint: before pushing again. hint: See the 'Note about
fast-forwards' in 'git push --help' for details.
What is it?
Your repo on GitHub already has a commit.
https://github.com/derkode/ForvoClient
This is normal when you create a repo with a README file.
You can fix this either by force pushing your local repo to GitHub, but you will lose the README file this way:
git push -u origin master -f
Or, you can merge the version on GitHub into yours and then push it back:
git pull origin master
git push -u origin master
Or, as #xbonez suggested, rebase your version on top of GitHub's version:
git fetch origin
git rebase origin/master
git push -u origin master
If you want to get rid of the commit that Github created for you with the README file, follow janos's answer. If you want to keep that commit, and push yours over it, simply pull down those changes and then push:
git fetch origin && git rebase origin/master && git push origin master

Git server and clone

I have create my git server with this link link
git clone working in server but when i clone my project on local machine
i have a problem
"warning: remote HEAD refers to nonexistent ref, unable to checkout."
i used for clone "git clone http://domain.com/project.git"
i used virtual machine(domain.com =192.168.1.196) for git server and windows for local machine.
Thanks
On the server run the following command in a new folder to initialize a new bare git repo...
git init --bare
On your local machine go to an existing folder of create a new one and run.
git init
Copy a file into this folder and execute.
git commit -am "New repository with a new file"
Then add your server as a remote.
git remote add myserver http://domain.com/project.git
Next step is to push to your server.
git push -u myserver master

Resources