Xavier's Blog

做更美好的自己

Git&Github使用

GitGithub版本控制

Git环境搭建

安装Git

brew install git

设置Git信息

git config --global user.name "XXX"
git config --global user.email XXX

Github环境搭建

安装GitHub Desktop

官网下载安装

配置SSH

ssh-keygen -t rsa -C "邮箱"
一直Enter,共三步
cd ~/.ssh
cat id_rsa.pub

复制出来,贴到Github的SSH处

修改提交方式为SSH

$ git config --global url."git@mygitlab.com:".insteadOf "http://mygitlab.com/"

// 其实就是在 `.gitconfig 增加了配置`
$ cat ~/.gitconfig

[url "git@mygitlab.com:"]
    insteadOf = http://mygitlab.com/

由于git 的仓库 进行初始化 的时候配置的是 https 的方式,

在 git push 的时候每次都要输入用户名 跟 密码。非常的不方便,

究其原因,该配置是在 ./git/config 文件中配置的

https 方式:

[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
	hideDotFiles = dotGitOnly
[remote "origin"]
	url = https://git.coding.net/coder/DMP.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "dev"]
	remote = origin
	merge = refs/heads/dev

git 方式:

[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
	hideDotFiles = dotGitOnly
[remote "origin"]
	url = git@git.coding.net:coder/DMP.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "dev"]
	remote = origin
	merge = refs/heads/dev
[gui]
	wmstate = normal
	geometry = 835x475+182+182 185 214

只要将

https: 
[remote "origin"]
   url = https://git.coding.net/asun_coder/DMP_JavaBackground.git
  fetch = +refs/heads/*:refs/remotes/origin/*

转换成

ssh:
[remote "origin"]
  url = git@git.coding.net:asun_coder/DMP_JavaBackground.git
  fetch = +refs/heads/*:refs/remotes/origin/*

转载请注明:Xavier’s Blog » Git&Github使用