Saturday, July 16, 2022

[FIXED] How not to ignore the message "not found in upstream origin, using HEAD instead"?

Issue

I am writing shell script to deploy a git branch from a remote repo.

This is the command I am using:

   git clone -q --depth=1 https://my.repourl.com/git-repo.git /my/destination/folder -b develop

The problem is, if the branch (develop in this case) is wrong, it just ignores and pulls from the master branch (?). I get this message:

  warning: Remote branch devel not found in upstream origin, using HEAD instead

I just want git to die/exit, if it does not find the branch specified. Any flags for that? Or any alternatives? git-archive did not work for some reason.


Solution

As twalberg comments, git ls-remote --heads https://my.repourl.com/git-repo.git is the command to use for checking if a branch exists on the remote side.

The question "How to check if remote branch exists on a given remote repository?" lists the other possibility:

git clone -n
git fetch
# parse git branch -r

The test (bash) can look like:

br=$(git ls-remote --heads https://my.repourl.com/git-repo.git|grep abranch)
if [[ "${br}" != "" ]]; then
  git clone -b aBranch ...
fi


Answered By - VonC
Answer Checked By - Willingham (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.