2021/06/05

macos下git使用


1、在账号 ~/.ssh/config 配置git仓库信息。

#码云
Host gitee.com
    HostName        gitee.com               #git地址
    UseKeychain     yes                     #使用macos秘钥串访问
    AddKeysToAgent  yes                     #ssh-agent
    User            git                     #git用户名
    IdentityFile    ~/.ssh/keys/yangxg      #ssh秘钥

2、将使用的ssh公钥和秘钥放到 ~/.ssh/keys 目录下,记得将公钥和秘钥权限设置为 600。

3、选择创建仓库的目录地方进行拉取仓库代码。

cd ~/Documents/work
git clone git@gitee.com/:yangxg/test.git

4、打开sourcetree -> 新建 -> 添加已经存在的本地仓库 -> 将第3步的项目引入到 sourcetree 下管理。

5、如果我们编写的代码需要同步到几个远程仓库,则可以前往仓库 .git/config 下配置不同远程仓库的地址。

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = git@gitee.com:yangxg/test.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[remote "origin-local"]
     url = git@localhost.com:local/test.git
     fetch = +refs/heads/*:refs/remotes/origin-local/*

配置完毕后即可马上在 sourcetree 下看到对应的多个远程仓库。