go-git icon indicating copy to clipboard operation
go-git copied to clipboard

How do you push a Git tag to a branch using a refspec?

Open twgcode opened this issue 4 years ago • 2 comments

How to implement the following commands: git push origin tagName1^{}:master

tagName1 is the name of a tag

twgcode avatar Nov 30 '21 10:11 twgcode

Hi! If I may, I had a similar case that I happen to have open-sourced recently. In my case, I am pushing a given sha, but the logic would probably be similar if the syntax is supported in the current implementation.

The implementation is here: https://github.com/adevinta/maiao/blob/9e7f216e631f5d1ca171d472792510cc18bd34fe/pkg/maiao/review.go#L218

More specifically, I used:

	refToPush := "tagName1^{}"
	refspecs := []config.RefSpec{config.RefSpec(refToPush+":refs/heads/master")}

	err = repo.Push(&git.PushOptions{
		RemoteName: "origin",
		RefSpecs:   refspecs,
	})

To support pushing with a given sha, I had to add support for it: https://github.com/go-git/go-git/pull/325

Hope this helps

tjamet avatar Dec 15 '21 23:12 tjamet

To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while.

This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed.

We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active.

Thanks for your understanding and cooperation!

github-actions[bot] avatar Apr 20 '24 07:04 github-actions[bot]