• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: GitHub tag not working correctly “This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.”

Resolved: GitHub tag not working correctly “This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.”

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I’m setting up a task in our azure pipeline to:
  • bump the project version number in version.txt
  • update the CHANGELOG
  • commit those two changes
  • create a tag with the new version number
  • push changes back to github

This is happening on our main branch.
My script looks like this:
echo "$new_version" > version.txt
git-changelog --tag "$new_version"
git add CHANGELOG
git add version.txt
git commit -m "Bump to release $new_version"
git tag -a "$new_version" -m "release $new_version"
git push origin "$new_version"
When I look back in GitHub, the updated CHANGELOG and version.txt don’t appear in main. However, the new tag exists. When I click to view the tag, I can see the two file changes in that commit. But I get a warning message on screen saying:

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.


GitHub Warning: This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Not sure what I’m doing wrong, and how to get the commit to apply to our main branch. The code checkout is being done by azure pipelines before my script runs, do I need to explicitly switch / checkout branches before running my commands?

Update


Azure pipelines checkout performs a checkout of the commit, not the branch. I needed to update my script to perform a checkout of main and then perform my stage and commits to that branch, and then push and tag worked as I was hoping.
git checkout main
#
# work to modify CHANGELOG and version.txt here...
#
git status -v -b
git add CHANGELOG
git add version.txt
git commit -m "Bump to release $new_version"
git push origin main
git tag "$new_version"
git push origin "$new_version"

Answer:

You are pushing the tag, not the branch. Push the branch.
In other words, you are complaining that this commit is not on main on GitHub, but you are not saying anything that would cause it to be on main on GitHub.

do I need to explicitly switch / checkout branches before running my commands?


Maybe. There’s nothing in your script that tells us whether you were on main when you committed. But even if you were, main is not what you pushed, and main is not what you pushed to.
If you are detached (i.e. not on any branch), it is still possible to push the tag to main. But the syntax for that is tricky because this is an annotated tag. See How do you push a Git tag to a branch using a refspec? for more.

If you have better answer, please add a comment about this, thank you!

azure-pipelines git github
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Visual Studio 2022 crashes when using breakpoints

24/03/2023

Resolved: How to get Union type from an array of objects in Flow?

24/03/2023

Resolved: Modify entity using Action in C#

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.