Reputation: 330
I have git installed on the machine but I keep getting the error message below when I try to run "git fetch origin/staging" in a shell script:
git fetch origin/staging
fatal: 'origin/staging' 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.
script returned exit code 128
My next shell commands would be
git checkout origin/staging
git merge dev
Upvotes: 0
Views: 576
Reputation: 330
This did the trick! The first step checks out the staging branch. The second step merges dev to staging. And the last step pushes staging to origin.
stage('Merge') {
steps {
git branch: 'staging', credentialsId: 'a-long-id', url: 'https://[email protected]/project/myrepo.git'
sh 'git merge dev'
sh 'git push origin staging'
}
}
Upvotes: 0
Reputation: 83527
fatal: 'origin/staging' does not appear to be a git repository
Note that origin/staging
refers to a remote tracking branch. The error message tells you that git fetch
requires the name of a remote instead. So try
git fetch origin
Then you should do
git checkout staging
which creates a new local branch named staging
which points at the same commit as the remote tracking branch origin/staging
. Then you can do
git merge dev
just as you have.
Upvotes: 2
Reputation: 21938
git fetch
is not expecting a <branch>
as first parameter, but a <remote>
instead, so you could just
git fetch origin
(check the doc for details)
However, you can fetch specifically for a branch on a remote, but you'll have to be explicit on the remote or your branch will be assumed as remote itself :
git fetch origin staging
(Note that we used here the name of the branch itself, not origin/staging
, the name of the remote-tracking branch which tracks it in your repository)
Upvotes: 2