--- layout: default menu_item: api title: Reference description: Version 0.26.1 menu_item: api return_to: "API Documentation Index": /api/ sections: "create": "#create" "createMatching": "#createMatching" "dwim": "#dwim" "ensureLog": "#ensureLog" "hasLog": "#hasLog" "isValidName": "#isValidName" "list": "#list" "lookup": "#lookup" "nameToId": "#nameToId" "normalizeName": "#normalizeName" "remove": "#remove" "symbolicCreate": "#symbolicCreate" "symbolicCreateMatching": "#symbolicCreateMatching" "updateTerminal": "#updateTerminal" "#cmp": "#cmp" "#delete": "#delete" "#dup": "#dup" "#isBranch": "#isBranch" "#isConcrete": "#isConcrete" "#isHead": "#isHead" "#isNote": "#isNote" "#isRemote": "#isRemote" "#isSymbolic": "#isSymbolic" "#isTag": "#isTag" "#isValid": "#isValid" "#name": "#name" "#owner": "#owner" "#peel": "#peel" "#rename": "#rename" "#resolve": "#resolve" "#setTarget": "#setTarget" "#shorthand": "#shorthand" "#symbolicSetTarget": "#symbolicSetTarget" "#symbolicTarget": "#symbolicTarget" "#target": "#target" "#targetPeel": "#targetPeel" "#toString": "#toString" "#type": "#type" "FORMAT": "#FORMAT" "TYPE": "#TYPE" --- ## Reference.create AsyncExperimental ```js Reference.create(repo, name, id, force, log_message).then(function(reference) { // Use reference }); ``` | Parameters | Type | | | --- | --- | --- | | repo | [Repository](/api/repository/) | Repository where that reference will live | | name | String | The name of the reference | | id | [Oid](/api/oid/) | The object id pointed to by the reference. | | force | Number | Overwrite existing references | | log_message | String | The one line long message to be appended to the reflog | | Returns | | | --- | --- | | [Reference](/api/reference/) | | ## Reference.createMatching AsyncExperimental ```js Reference.createMatching(repo, name, id, force, current_id, log_message).then(function(reference) { // Use reference }); ``` | Parameters | Type | | | --- | --- | --- | | repo | [Repository](/api/repository/) | Repository where that reference will live | | name | String | The name of the reference | | id | [Oid](/api/oid/) | The object id pointed to by the reference. | | force | Number | Overwrite existing references | | current_id | [Oid](/api/oid/) | The expected value of the reference at the time of update | | log_message | String | The one line long message to be appended to the reflog | | Returns | | | --- | --- | | [Reference](/api/reference/) | | ## Reference.dwim Async ```js Reference.dwim(repo, id, callback).then(function(reference) { // Use reference }); ``` Retrieves the reference by it's short name | Parameters | Type | | | --- | --- | --- | | repo | [Repository](/api/repository/) | The repo that the reference lives in | | id | String, [Reference](/api/reference/) | The reference to lookup | | callback | Function | | | Returns | | | --- | --- | | [Reference](/api/reference/) | | ## Reference.ensureLog SyncExperimental ```js var result = Reference.ensureLog(repo, refname); ``` | Parameters | Type | | | --- | --- | --- | | repo | [Repository](/api/repository/) | the repository | | refname | String | the reference's name | | Returns | | | --- | --- | | Number | 0 or an error code. | ## Reference.hasLog SyncExperimental ```js var result = Reference.hasLog(repo, refname); ``` | Parameters | Type | | | --- | --- | --- | | repo | [Repository](/api/repository/) | the repository | | refname | String | the reference's name | | Returns | | | --- | --- | | Number | 0 when no reflog can be found, 1 when it exists; otherwise an error code. | ## Reference.isValidName SyncExperimental ```js var result = Reference.isValidName(refname); ``` | Parameters | Type | | | --- | --- | --- | | refname | String | name to be checked. | | Returns | | | --- | --- | | Number | 1 if the reference name is acceptable; 0 if it isn't | ## Reference.list AsyncExperimental ```js Reference.list(repo).then(function(array) { // Use array }); ``` | Parameters | Type | | | --- | --- | --- | | repo | [Repository](/api/repository/) | Repository where to find the refs | | Returns | | | --- | --- | | Array | | ## Reference.lookup Async ```js Reference.lookup(repo, id, callback).then(function(reference) { // Use reference }); ``` Retrieves the reference pointed to by the oid | Parameters | Type | | | --- | --- | --- | | repo | [Repository](/api/repository/) | The repo that the reference lives in | | id | String, [Reference](/api/reference/) | The reference to lookup | | callback | Function | | | Returns | | | --- | --- | | [Reference](/api/reference/) | | ## Reference.nameToId AsyncExperimental ```js Reference.nameToId(repo, name).then(function(oid) { // Use oid }); ``` | Parameters | Type | | | --- | --- | --- | | repo | [Repository](/api/repository/) | The repository in which to look up the reference | | name | String | The long name for the reference (e.g. HEAD, refs/heads/master, refs/tags/v0.1.0, ...) | | Returns | | | --- | --- | | [Oid](/api/oid/) | | ## Reference.normalizeName SyncExperimental ```js var result = Reference.normalizeName(buffer_out, buffer_size, name, flags); ``` | Parameters | Type | | | --- | --- | --- | | buffer_out | String | User allocated buffer to store normalized name | | buffer_size | Number | Size of buffer_out | | name | String | Reference name to be checked. | | flags | Number | Flags to constrain name validation rules - see the GIT_REFERENCE_FORMAT constants above. | | Returns | | | --- | --- | | Number | 0 on success, GIT_EBUFS if buffer is too small, GIT_EINVALIDSPEC or an error code. | ## Reference.remove SyncExperimental ```js var result = Reference.remove(repo, name); ``` | Parameters | Type | | | --- | --- | --- | | repo | [Repository](/api/repository/) | | | name | String | The reference to remove | | Returns | | | --- | --- | | Number | 0 or an error code | ## Reference.symbolicCreate AsyncExperimental ```js Reference.symbolicCreate(repo, name, target, force, log_message).then(function(reference) { // Use reference }); ``` | Parameters | Type | | | --- | --- | --- | | repo | [Repository](/api/repository/) | Repository where that reference will live | | name | String | The name of the reference | | target | String | The target of the reference | | force | Number | Overwrite existing references | | log_message | String | The one line long message to be appended to the reflog | | Returns | | | --- | --- | | [Reference](/api/reference/) | | ## Reference.symbolicCreateMatching AsyncExperimental ```js Reference.symbolicCreateMatching(repo, name, target, force, current_value, log_message).then(function(reference) { // Use reference }); ``` | Parameters | Type | | | --- | --- | --- | | repo | [Repository](/api/repository/) | Repository where that reference will live | | name | String | The name of the reference | | target | String | The target of the reference | | force | Number | Overwrite existing references | | current_value | String | The expected value of the reference when updating | | log_message | String | The one line long message to be appended to the reflog | | Returns | | | --- | --- | | [Reference](/api/reference/) | | ## Reference.updateTerminal Async ```js Reference.updateTerminal(repo, refName, oid, logMessage, signature).then(function() { // method complete}); ``` Given a reference name, follows symbolic links and updates the direct reference to point to a given OID. Updates the reflog with a given message. | Parameters | Type | | | --- | --- | --- | | repo | [Repository](/api/repository/) | The repo where the reference and objects live | | refName | String | The reference name to update | | oid | [Oid](/api/oid/) | The target OID that the reference will point to | | logMessage | String | The reflog message to be writted | | signature | [Signature](/api/signature/) | Optional signature to use for the reflog entry | ## Reference#cmp SyncExperimental ```js var result = reference.cmp(ref2); ``` | Parameters | Type | | --- | --- | --- | | ref2 | [Reference](/api/reference/) | The second git_reference | | Returns | | | --- | --- | | Number | 0 if the same, else a stable but meaningless ordering. | ## Reference#delete SyncExperimental ```js var result = reference.delete(); ``` | Returns | | | --- | --- | | Number | 0, GIT_EMODIFIED or an error code | ## Reference#dup AsyncExperimental ```js reference.dup().then(function(reference) { // Use reference }); ``` | Returns | | | --- | --- | | [Reference](/api/reference/) | the copy | ## Reference#isBranch SyncExperimental ```js var result = reference.isBranch(); ``` | Returns | | | --- | --- | | Number | 1 when the reference lives in the refs/heads namespace; 0 otherwise. | ## Reference#isConcrete Sync ```js var boolean = reference.isConcrete(); ``` Returns true if this reference is not symbolic | Returns | | | --- | --- | | Boolean | | ## Reference#isHead Sync ```js var boolean = reference.isHead(); ``` Returns if the ref is pointed at by HEAD | Returns | | | --- | --- | | Boolean | | ## Reference#isNote SyncExperimental ```js var result = reference.isNote(); ``` | Returns | | | --- | --- | | Number | 1 when the reference lives in the refs/notes namespace; 0 otherwise. | ## Reference#isRemote SyncExperimental ```js var result = reference.isRemote(); ``` | Returns | | | --- | --- | | Number | 1 when the reference lives in the refs/remotes namespace; 0 otherwise. | ## Reference#isSymbolic Sync ```js var boolean = reference.isSymbolic(); ``` Returns true if this reference is symbolic | Returns | | | --- | --- | | Boolean | | ## Reference#isTag SyncExperimental ```js var result = reference.isTag(); ``` | Returns | | | --- | --- | | Number | 1 when the reference lives in the refs/tags namespace; 0 otherwise. | ## Reference#isValid Sync ```js var boolean = reference.isValid(); ``` Returns true if this reference is valid | Returns | | | --- | --- | | Boolean | | ## Reference#name SyncExperimental ```js var string = reference.name(); ``` | Returns | | | --- | --- | | String | the full name for the ref | ## Reference#owner SyncExperimental ```js var repository = reference.owner(); ``` | Returns | | | --- | --- | | [Repository](/api/repository/) | the repo | ## Reference#peel AsyncExperimental ```js reference.peel(type).then(function(object) { // Use object }); ``` | Parameters | Type | | --- | --- | --- | | type | Number | The type of the requested object (GIT_OBJECT_COMMIT, GIT_OBJECT_TAG, GIT_OBJECT_TREE, GIT_OBJECT_BLOB or GIT_OBJECT_ANY). | | Returns | | | --- | --- | | [Object](/api/object/) | | ## Reference#rename AsyncExperimental ```js reference.rename(new_name, force, log_message).then(function(reference) { // Use reference }); ``` | Parameters | Type | | --- | --- | --- | | new_name | String | The new name for the reference | | force | Number | Overwrite an existing reference | | log_message | String | The one line long message to be appended to the reflog | | Returns | | | --- | --- | | [Reference](/api/reference/) | | ## Reference#resolve AsyncExperimental ```js reference.resolve().then(function(reference) { // Use reference }); ``` | Returns | | | --- | --- | | [Reference](/api/reference/) | | ## Reference#setTarget AsyncExperimental ```js reference.setTarget(id, log_message).then(function(reference) { // Use reference }); ``` | Parameters | Type | | --- | --- | --- | | id | [Oid](/api/oid/) | The new target OID for the reference | | log_message | String | The one line long message to be appended to the reflog | | Returns | | | --- | --- | | [Reference](/api/reference/) | | ## Reference#shorthand SyncExperimental ```js var string = reference.shorthand(); ``` | Returns | | | --- | --- | | String | the human-readable version of the name | ## Reference#symbolicSetTarget AsyncExperimental ```js reference.symbolicSetTarget(target, log_message).then(function(reference) { // Use reference }); ``` | Parameters | Type | | --- | --- | --- | | target | String | The new target for the reference | | log_message | String | The one line long message to be appended to the reflog | | Returns | | | --- | --- | | [Reference](/api/reference/) | | ## Reference#symbolicTarget SyncExperimental ```js var string = reference.symbolicTarget(); ``` | Returns | | | --- | --- | | String | the name if available, NULL otherwise | ## Reference#target SyncExperimental ```js var oid = reference.target(); ``` | Returns | | | --- | --- | | [Oid](/api/oid/) | the oid if available, NULL otherwise | ## Reference#targetPeel SyncExperimental ```js var oid = reference.targetPeel(); ``` | Returns | | | --- | --- | | [Oid](/api/oid/) | the oid if available, NULL otherwise | ## Reference#toString Sync ```js var string = reference.toString(); ``` Returns the name of the reference. | Returns | | | --- | --- | | String | | ## Reference#type SyncExperimental ```js var result = reference.type(); ``` | Returns | | | --- | --- | | Number | the type | ## Reference.FORMAT ENUM | Flag | Value | | --- | --- | --- | | Reference.FORMAT.NORMAL | 0 | | Reference.FORMAT.ALLOW_ONELEVEL | 1 | | Reference.FORMAT.REFSPEC_PATTERN | 2 | | Reference.FORMAT.REFSPEC_SHORTHAND | 4 | ## Reference.TYPE ENUM | Flag | Value | | --- | --- | --- | | Reference.TYPE.INVALID | 0 | | Reference.TYPE.DIRECT | 1 | | Reference.TYPE.SYMBOLIC | 2 | | Reference.TYPE.ALL | 3 |