{
    "mode": "man",
    "parameter": "GIT-UPDATE-REF",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/GIT-UPDATE-REF/1/json",
    "generated": "2026-06-13T21:54:31Z",
    "synopsis": "git update-ref [-m <reason>] [--no-deref] (-d <ref> [<oldvalue>] | [--create-reflog] <ref> <newvalue> [<oldvalue>] | --stdin [-z])",
    "sections": {
        "NAME": {
            "content": "git-update-ref - Update the object name stored in a ref safely\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "git update-ref [-m <reason>] [--no-deref] (-d <ref> [<oldvalue>] | [--create-reflog] <ref> <newvalue> [<oldvalue>] | --stdin [-z])\n\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Given two arguments, stores the <newvalue> in the <ref>, possibly dereferencing the symbolic\nrefs. E.g. git update-ref HEAD <newvalue> updates the current branch head to the new object.\n\nGiven three arguments, stores the <newvalue> in the <ref>, possibly dereferencing the\nsymbolic refs, after verifying that the current value of the <ref> matches <oldvalue>. E.g.\ngit update-ref refs/heads/master <newvalue> <oldvalue> updates the master branch head to\n<newvalue> only if its current value is <oldvalue>. You can specify 40 \"0\" or an empty string\nas <oldvalue> to make sure that the ref you are creating does not exist.\n\nIt also allows a \"ref\" file to be a symbolic pointer to another ref file by starting with the\nfour-byte header sequence of \"ref:\".\n\nMore importantly, it allows the update of a ref file to follow these symbolic pointers,\nwhether they are symlinks or these \"regular file symbolic refs\". It follows real symlinks\nonly if they start with \"refs/\": otherwise it will just try to read them and update them as a\nregular file (i.e. it will allow the filesystem to follow them, but will overwrite such a\nsymlink to somewhere else with a regular filename).\n\nIf --no-deref is given, <ref> itself is overwritten, rather than the result of following the\nsymbolic pointers.\n\nIn general, using\n\ngit update-ref HEAD \"$head\"\n\nshould be a lot safer than doing\n\necho \"$head\" > \"$GITDIR/HEAD\"\n\nboth from a symlink following standpoint and an error checking standpoint. The \"refs/\" rule\nfor symlinks means that symlinks that point to \"outside\" the tree are safe: they’ll be\nfollowed for reading but not for writing (so we’ll never write through a ref symlink to some\nother tree, if you have copied a whole archive by creating a symlink tree).\n\nWith -d flag, it deletes the named <ref> after verifying it still contains <oldvalue>.\n\nWith --stdin, update-ref reads instructions from standard input and performs all\nmodifications together. Specify commands of the form:\n\nupdate SP <ref> SP <newvalue> [SP <oldvalue>] LF\ncreate SP <ref> SP <newvalue> LF\ndelete SP <ref> [SP <oldvalue>] LF\nverify SP <ref> [SP <oldvalue>] LF\noption SP <opt> LF\nstart LF\nprepare LF\ncommit LF\nabort LF\n\nWith --create-reflog, update-ref will create a reflog for each ref even if one would not\nordinarily be created.\n\nQuote fields containing whitespace as if they were strings in C source code; i.e., surrounded\nby double-quotes and with backslash escapes. Use 40 \"0\" characters or the empty string to\nspecify a zero value. To specify a missing value, omit the value and its preceding SP\nentirely.\n\nAlternatively, use -z to specify in NUL-terminated format, without quoting:\n\nupdate SP <ref> NUL <newvalue> NUL [<oldvalue>] NUL\ncreate SP <ref> NUL <newvalue> NUL\ndelete SP <ref> NUL [<oldvalue>] NUL\nverify SP <ref> NUL [<oldvalue>] NUL\noption SP <opt> NUL\nstart NUL\nprepare NUL\ncommit NUL\nabort NUL\n\nIn this format, use 40 \"0\" to specify a zero value, and use the empty string to specify a\nmissing value.\n\nIn either format, values can be specified in any form that Git recognizes as an object name.\nCommands in any other format or a repeated <ref> produce an error. Command meanings are:\n\nupdate\nSet <ref> to <newvalue> after verifying <oldvalue>, if given. Specify a zero <newvalue>\nto ensure the ref does not exist after the update and/or a zero <oldvalue> to make sure\nthe ref does not exist before the update.\n\ncreate\nCreate <ref> with <newvalue> after verifying it does not exist. The given <newvalue> may\nnot be zero.\n\ndelete\nDelete <ref> after verifying it exists with <oldvalue>, if given. If given, <oldvalue>\nmay not be zero.\n\nverify\nVerify <ref> against <oldvalue> but do not change it. If <oldvalue> is zero or missing,\nthe ref must not exist.\n\noption\nModify behavior of the next command naming a <ref>. The only valid option is no-deref to\navoid dereferencing a symbolic ref.\n\nstart\nStart a transaction. In contrast to a non-transactional session, a transaction will\nautomatically abort if the session ends without an explicit commit. This command may\ncreate a new empty transaction when the current one has been committed or aborted\nalready.\n\nprepare\nPrepare to commit the transaction. This will create lock files for all queued reference\nupdates. If one reference could not be locked, the transaction will be aborted.\n\ncommit\nCommit all reference updates queued for the transaction, ending the transaction.\n\nabort\nAbort the transaction, releasing all locks if the transaction is in prepared state.\n\nIf all <ref>s can be locked with matching <oldvalue>s simultaneously, all modifications are\nperformed. Otherwise, no modifications are performed. Note that while each individual <ref>\nis updated or deleted atomically, a concurrent reader may still see a subset of the\nmodifications.\n",
            "subsections": []
        },
        "LOGGING UPDATES": {
            "content": "If config parameter \"core.logAllRefUpdates\" is true and the ref is one under \"refs/heads/\",\n\"refs/remotes/\", \"refs/notes/\", or a pseudoref like HEAD or ORIGHEAD; or the file\n\"$GITDIR/logs/<ref>\" exists then git update-ref will append a line to the log file\n\"$GITDIR/logs/<ref>\" (dereferencing all symbolic refs before creating the log name)\ndescribing the change in ref value. Log lines are formatted as:\n\noldsha1 SP newsha1 SP committer LF\n\nWhere \"oldsha1\" is the 40 character hexadecimal value previously stored in <ref>, \"newsha1\"\nis the 40 character hexadecimal value of <newvalue> and \"committer\" is the committer’s name,\nemail address and date in the standard Git committer ident format.\n\nOptionally with -m:\n\noldsha1 SP newsha1 SP committer TAB message LF\n\nWhere all fields are as described above and \"message\" is the value supplied to the -m option.\n\nAn update will fail (without changing <ref>) if the current user is unable to create a new\nlog file, append to the existing log file or does not have committer information available.\n",
            "subsections": []
        },
        "GIT": {
            "content": "Part of the git(1) suite\n\n\n\nGit 2.34.1                                   02/26/2026                            GIT-UPDATE-REF(1)",
            "subsections": []
        }
    },
    "summary": "git-update-ref - Update the object name stored in a ref safely",
    "flags": [],
    "examples": [],
    "see_also": [],
    "tldr": {
        "source": "official",
        "description": "Git command for creating, updating, and deleting Git refs.",
        "examples": [
            {
                "description": "Delete a ref, useful for soft resetting the first commit",
                "command": "git update-ref -d {{HEAD}}"
            },
            {
                "description": "Update ref with a message",
                "command": "git update-ref -m {{message}} {{HEAD}} {{4e95e05}}"
            }
        ]
    }
}