https://github.com/runemadsen/easygit
Higher level API for git2go
https://github.com/runemadsen/easygit
Last synced: 2 months ago
JSON representation
Higher level API for git2go
- Host: GitHub
- URL: https://github.com/runemadsen/easygit
- Owner: runemadsen
- Created: 2017-01-19T16:24:23.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-26T16:49:30.000Z (about 8 years ago)
- Last Synced: 2025-04-01T21:51:56.674Z (2 months ago)
- Language: Go
- Size: 19.5 KB
- Stars: 5
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# easygit
This is a set of helper functions for git2go to make the API more accessible.
## Usage
```go
import "github.com/runemadsen/easygit"func main() {
// Clones a repo to a local path. Credentials are not used if
// it's a public repo.
err := easygit.Clone("https://github.com/runemadsen/testrepo.git", "/my/repo/path", "user", "password")
fmt.Println(err.(*git.GitError).Code) // if -7, it was wrong credentials for private repo// Add all files to index. Similar to 'git add .'
err := easygit.AddAll("path/to/repo")// Commit files in the index. If repo is commit, it will also create HEAD
err := easygit.Commit("path/to/repo", "My commit message", "Git Name", "Git Email")// List all local branches. Similar to 'git branch'
branchNames := easygit.ListBranches("path/to/repo")// Get the current local branch
currentBranch := easyGit.CurrentBranch("path/to/repo")// Deletes a branch
err := easygit.DeleteBranch("path/to/repo", "mybranch")// Creates a branch from another branch.
err := easygit.CreateBranch("path/to/repo", "master", "newbranch")// Pushes a branch to a HTTPS remote. Similar to 'git push origin master'
err := easygit.PushBranch("path/to/repo", "origin", "master", "httpsuser", "httpspassword")
fmt.Println(err.(*git.GitError).Code) // if -7, it was wrong credentials// Pulls and merges a branch from a remote. This function is a bit opinionated: If the pull
// results in a conflict, it will reset back to the current state and return an error saying "conflict".
// This will not leave the repo in a conflict state, but leave the branch in the state that it was before the pull.
// If there is no conflict, it will create a merge commit and merge the local and remote branch
// (which is why it needs the last signature params)
err := PullBranch("path/to/repo", "origin", "master", "httpsuser", "httpspassword", "Git Name", "Git Email")// Checks out a branch. Similar to 'git checkout slave'
err := easygit.CheckoutBranch("path/to/repo", "mybranch")
}
```