git.el
git.el copied to clipboard
An Elisp API for programmatically using Git
Git.el
An Elisp API for programmatically using Git.
Installation
Add git to your Cask file:
(depends-on "git")
API
Predicates
- git-repo?
(directory) - git-branch?
(branch) - git-tag?
(tag) - git-on-branch?
(branch) - git-remote?
(name)
Info
- git-on-branch
() - git-branches
() - git-log
(&optional branch) - git-remotes
() - git-stashes
() - git-tags
() - git-untracked-files
() - git-staged-files
()
Destructive
- git-add
(&rest files) - git-branch
(branch) - git-checkout
(branch) - git-commit
(message &rest files) - git-init
(&optional dir bare) - git-remote-add
(name url) - git-remote-remove
(name) - git-reset
(&optional commit mode) - git-rm
(path) - git-stash
(&optional message) - git-stash-pop
(&optional name) - git-stash-apply
(&optional name) - git-tag
(tag)
Non local
- git-clone
(url &optional dir) - git-fetch
(&optional repo ref) - git-pull
(&optional repo ref) - git-push
(&optional repo ref)
Misc
- git-run
(command &rest args)
Documentation and examples
git-repo? (directory)
Return true if there is a git repo in DIRECTORY, false otherwise.
(git-repo? "/path/to/git/repo") ;; => t
(git-repo? "/path/to/svn/repo") ;; => nil
git-branch? (branch)
Return true if there's a branch called BRANCH.
(git-branch? "existing") ;; => t
(git-branch? "non-existing") ;; => nil
git-tag? (tag)
Return true if there's a tag called TAG.
(git-tag? "existing") ;; => t
(git-tag? "non-existing") ;; => nil
git-on-branch? (branch)
Return true if BRANCH is currently active.
(git-on-branch? "current") ;; => t
(git-on-branch? "other") ;; => nil
git-remote? (name)
Return true if remote with NAME exists, false otherwise.
(git-remote? "existing") ;; => t
(git-remote? "non-existing") ;; => nil
git-on-branch ()
Return currently active branch.
(git-on-branch) ;; => "current-branch"
git-branches ()
List all available branches.
(git-branches) ;; => '("master" "foo" "bar")
git-log (&optional branch)
Log history on BRANCH.
(git-log)
(git-log "foo")
git-remotes ()
Return list of all remotes.
(git-remotes) ;; => '("remote-1" "remote-2")
git-stashes ()
Return list of stashes.
(git-stashes) ;; => (:name "..." :branch "..." :message "...")
git-tags ()
Return list of all tags.
(git-tags) ;; => '("tag-1" "tag-2")
git-untracked-files ()
Return list of untracked files.
(git-untracked-files) ;; => '("file-1" "file-2")
git-staged-files ()
Return list of staged files.
(git-staged-files) ;; => '("file-1" "file-2")
git-add (&rest files)
Add PATH or everything.
(git-add)
(git-add "foo")
(git-add "foo" "bar")
git-branch (branch)
Create BRANCH.
(git-branch "branch")
git-checkout (branch)
Checkout REF.
(git-checkout "branch")
git-commit (message &rest files)
Commit FILES (or added files) with MESSAGE.
(git-commit "add foo" "foo")
(git-commit "add foo and bar" "foo" "bar")
(git-commit "add em all")
git-init (&optional dir bare)
Create new Git repo at DIR (or `git-repo').
If BARE is true, create a bare repo.
(git-init)
(git-init "foo")
(git-init "foo" :bare)
git-remote-add (name url)
Add remote with NAME and URL.
(git-remote-add "foo" "[email protected]")
git-remote-remove (name)
Remove remote with NAME.
(git-remote-remove "foo")
git-reset ()
Reset to COMMIT with MODE.
(git-reset)
(git-reset "HEAD~1" 'hard)
git-rm (path)
Remove PATH.
To remove directory, use RECURSIVE argument.
(git-rm "foo")
(git-rm "bar" :recursive)
git-stash (&optional message)
Stash changes in a dirty tree with MESSAGE.
If a stash was created, the name of the stash is returned, otherwise nil is returned.
(git-stash)
(git-stash "foo")
git-stash-pop (&optional name)
Apply and remove stash with NAME (or first stash).
(git-stash-pop)
(git-stash-pop "stash@{3}")
git-stash-apply (&optional name)
Apply and keep stash with NAME (or first stash).
(git-stash-apply)
(git-stash-apply "stash@{3}")
git-tag (tag)
Create TAG.
(git-tag "tag")
git-clone (url &optional dir)
Clone URL to DIR (if present).
(git-clone "[email protected]")
(git-clone "[email protected]" "bar")
git-fetch (&optional repo ref)
Fetch REPO.
(git-fetch)
(git-fetch "origin" "master")
git-pull (&optional repo ref)
Pull REF from REPO.
(git-pull)
(git-pull "origin" "master")
git-push (&optional repo ref)
Push REF to REPO.
(git-push)
(git-push "origin" "master")
git-run (command &rest args)
Run git COMMAND with ARGS.
(git-run "log")
(git-run "log" "--name-only")
;; ...
Notes
For each command, you can add arguments using git-args.
(let ((git-args "--hard"))
(git-reset "HEAD"))
Contribution
Be sure to!
Install Cask if you haven't already.
Run the unit tests with:
$ make test
Do not change README.md directly. If you want to change the README
or if you change any function comments, update the README with:
$ make docs