参见 Git 官网
# 第一次安装时没有该目录
$ cd ~/.ssh
# rsa算法,C后面接邮箱账号;表示根据邮箱生成key
$ ssh-keygen -t rsa -C "example@example.com"
登陆Github-->Account Settings--->SSH Public keys ---> add another public keys
$ ssh -T git@github.com
## 当电脑只需用到一个Github账号时,可以使用全局的用户信息
$ git config --global user.name "name"//用户名
$ git config --global user.email "example@example.com"//邮箱
$ssh-keygen -t rsa -C "example@example.com"
$ssh-add ~/.ssh/id_rsa_second
#默认的github
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa
#第二个github
Host github_second
HostName github.com
IdentityFile ~/.ssh/id_rsa_second
git clone git@github_second:username/reponame
git config --global --unset user.name
git config --global --unset user.email
git config user.email "example@example.com"
git config user.name "name"
Tip:当对git命令不熟悉时,可以通过
$git xxx --help
查看帮助文档,注意xxx代表不熟悉的命令,比如clone。也可以查看廖雪峰的Git教程和Git官网学习。
# 电脑中只有一个github账号时
git clone https://github.com/username/reponame
# 电脑中有两个个github账号时,github_second表示第二个账号的host
git clone git@github_second:username/reponame
# 进入仓库文件夹(工作区)
$cd reponame
# 强制移除所有文件
$git rm -rf .
可以复制要添加的文件到仓库文件夹(工作区)中,然后执行命令
$git add *
$git commit -a -m "注释"
# origin表示源仓库
$git push origin master
# 切换到分支newbranch,-b表示没有就创建(branch/build)
$git checkout -b newbranch
# 创建文件hello
$touch hello
# 添加到暂存区
$git add hello
# 提交到本地仓库
$git commit -m "add a file hello"
# 提交到远程仓库的newbranch分支,-u表示set-upstream
$git push -u origin newbranch
在项目的Settings-->Branches下可以修改Default branch
修改默认分支,其实就是把版本库的头指针HEAD
指向了其他分支,通过$git branch -r
(r表示remotes)可以查看所有远程分支和默认分支。
$git merge newbranch
# 切换到master分支工作
$git checkout master
Git在删除分支时为避免数据丢失,默认禁止删除尚未合并的分支。所以,如果分支尚未合并,使用$git branch -d newbranch
会报错。
使用$git branch -D newbranch
可以强制删除分支。
$git push origin --delete testbranch
每个开发者都从源仓库中Fork代码,然后独立开发。完了,在pull request合并到源仓库中。
# 电脑中只有一个github账号时
git clone https://github.com/username/reponame
# 电脑中有两个个github账号时,github_second表示第二个账号的host
git clone git@github_second:username/reponame
>>> git checkout develop
# 切换到`develop`分支
>>> git checkout -b feature-discuss
# 分出一个功能性分支
>> touch discuss.js
# 假装discuss.js就是我们要开发的功能
>> git add .
>> git commit -m 'finish discuss feature'
# 提交更改
>>> git checkout develop
# 回到develop分支
>>> git merge --no-ff feature-discuss
# 把做好的功能合并到develop中
>>> git branch -d feature-discuss
# 删除功能性分支
>>> git push origin develop
# 把develop提交到自己的远程仓库中
点击绿色按钮pull request,将自己仓库的分支合并到源分支中
>> git checkout develop
# 进入他本地的develop分支
>> git checkout -b khhhshhh-develop
# 从develop分支中分出一个叫khhhshhh-develop的测试分支测试我的代码
>> git pull https://github.com/khhhshhh/practice.git develop
# 把我的代码pull到测试分支中,进行测试
>> git checkout develop
>> git merge --no-ff khhhshhh-develop
>> git push origin develop
使用热键可以便捷地使用 Github。使用热键 ?
查看所有可用的热键,也可以访问 Github Help 获取详细的热键列表。常用的热键如下:
原文:https://www.cnblogs.com/lshare/p/11334737.html