currentBranch
Get the name of the branch currently pointed to by .git/HEAD
| param | type [= default] | description |
|---|---|---|
| fs | FsClient | a file system implementation |
| dir | string | The working tree directory path |
| gitdir | string = join(dir,'.git') | The git directory path |
| fullname | boolean = false | Return the full path (e.g. "refs/heads/main") instead of the abbreviated form. |
| test | boolean = false | If the current branch doesn't actually exist (such as right after git init) then return undefined. |
| return | Promise<(string | void)> | The name of the current branch or undefined if the HEAD is detached. |
Example Code:
// Get the current branch name
let branch = await git.currentBranch({
fs,
dir: '/tutorial',
fullname: false
})
console.log(branch)
Tip: If you need a clean slate, expand and run this snippet to clean up the file system.
window.fs = new LightningFS('fs', { wipe: true })
window.pfs = window.fs.promises
console.log('done')