Ai
5 Star 11 Fork 7

Gitee 极速下载/go-git

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/src-d/go-git
克隆/下载
main.go 1.68 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"fmt"
"gopkg.in/src-d/go-git.v4"
. "gopkg.in/src-d/go-git.v4/_examples"
"gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/storage/memory"
)
// Example of how to:
// - Create a new in-memory repository
// - Create a new remote named "example"
// - List remotes and print them
// - Pull using the new remote "example"
// - Iterate the references again, but only showing hash references, not symbolic ones
// - Remove remote "example"
func main() {
// Create a new repository
Info("git init")
r, err := git.Init(memory.NewStorage(), nil)
CheckIfError(err)
// Add a new remote, with the default fetch refspec
Info("git remote add example https://github.com/git-fixtures/basic.git")
_, err = r.CreateRemote(&config.RemoteConfig{
Name: "example",
URLs: []string{"https://github.com/git-fixtures/basic.git"},
})
CheckIfError(err)
// List remotes from a repository
Info("git remotes -v")
list, err := r.Remotes()
CheckIfError(err)
for _, r := range list {
fmt.Println(r)
}
// Fetch using the new remote
Info("git fetch example")
err = r.Fetch(&git.FetchOptions{
RemoteName: "example",
})
CheckIfError(err)
// List the branches
// > git show-ref
Info("git show-ref")
refs, err := r.References()
CheckIfError(err)
err = refs.ForEach(func(ref *plumbing.Reference) error {
// The HEAD is omitted in a `git show-ref` so we ignore the symbolic
// references, the HEAD
if ref.Type() == plumbing.SymbolicReference {
return nil
}
fmt.Println(ref)
return nil
})
CheckIfError(err)
// Delete the example remote
Info("git remote rm example")
err = r.DeleteRemote("example")
CheckIfError(err)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/go-git.git
git@gitee.com:mirrors/go-git.git
mirrors
go-git
go-git
v4.0.0

搜索帮助