Update target refs to match source commitish.
Update target refs to match source commitish, enabling precise ref management via the GitHub API.
ghup update-ref [flags] -s <source-commitish> <target-ref> ...
The update-ref
command enables you to update one or more references (branches, tags, or any ref) to point to a specific commit. This is a lower-level command that gives you direct control over repository references.
Common use cases include:
- Syncing multiple branches/tags to point to the same commit
- Creating or updating branches or tags programmatically
- Managing references that are not standard branches or tags
This command is particularly useful in CI/CD pipelines where you need to update multiple references as part of automated processes.
Source commitish may also be passed via the GHUP_SOURCE
environment variable, and target refs via GHUP_TARGETS
(space-delimited).
-s, --source string source commitish
-f, --force force update if ref exists
-h, --help help for update-ref
# Update a branch to match another branch
ghup update-ref -s main refs/heads/production
# Update a tag to point to the latest commit on main
ghup update-ref -s main refs/tags/latest
# Update multiple refs in one command
ghup update-ref -s v1.0.0 refs/heads/stable refs/tags/production-ready
# Force update an existing ref
ghup update-ref -s main refs/heads/production -f
# Update refs using environment variables
export GHUP_SOURCE=main
export GHUP_TARGETS="refs/heads/production refs/tags/latest"
ghup update-ref
The command returns a JSON (or YAML) object with the following structure:
{
"repository": "owner/repo",
"source": {
"commitish": "main",
"sha": "full-sha-hash"
},
"target": [
{
"ref": "refs/heads/production",
"old": "previous-sha-if-updated",
"sha": "new-sha-hash",
"updated": true
},
{
"ref": "refs/tags/latest",
"old": "previous-sha-if-updated",
"sha": "new-sha-hash",
"updated": true
}
]
}
source
: Information about the source commitishtarget
: Array of information about each target ref that was processedref
: The full reference nameold
: The previous SHA (only present if updated)sha
: The new SHA the ref points toupdated
: Whether the ref was actually changederror
: Error message if updating this specific ref failed
If an error occurs with the source commitish, the output will include an error message in the source object.