1
2
| git config --global user.name "Your github name"
git config --global user.email "Your email address for github"
|
1
| ssh-keygen -t rsa -C "Your email address"
|
注意:如果你之前使用其他GitHub账号与本地进行过SSH配置,那么你需要重新指定key生成的路径,以免覆盖之前的SSH造成错误。
1
2
| eval $(ssh-agent -s)
ssh-add /your/Path/to/ssh/private/key/id_rsa
|
复制id_rsa.pub中的全部内容,添加到GitHub账户设置中的SSH Keys中即可。
1
2
3
4
5
6
7
8
9
10
11
| //在本地你想要作为仓库的文件夹里进行仓库配置的初始化
git init
//主要是防止添加空文件到缓冲区,如果本来有文件可以直接使用git add [filename]
touch README
git add README
git commit -m "README/your comments"
//创建一个名为master的分支
git branch -M master
//和远程仓库进行绑定
git remote add origin git@github.com:ssh-link-of-remote-repository
git push -u origin master
|
1
2
3
4
5
6
7
8
| git init
//把远程库的内容拉取到本地文件夹当中
git pull origin branch-name ssh-link-of-remote-repository
//在本地修改文件之后点击保存
git add .
git commit -m 'Your comment on this commit'
git push origin branch-name
git switch branch-name //切换分支
|
git add .:不添加参数,默认为将修改的文件和未跟踪新添加的文件添加到git系统的暂存区,不包括删除的文件。git add -u .:将已跟踪文件中的修改和删除文件添加到暂存区,不包括新增加的文件。git add -A .:将所有的已跟踪的文件的修改与删除和新增的未跟踪的文件都添加到暂存区。
git commit 主要是将暂存区里的改动给提交到本地的版本库。每次使用git commit 命令我们都会在本地版本库生成一个40位的哈希值,这个哈希值也叫commit-id,commit-id 在版本回退的时候是非常有用的,它相当于一个快照,可以在未来的任何时候通过与git reset的组合命令回到这里。
1
2
3
4
5
6
| //添加本地分支
git branch -M branch-name
//删除本地分支
git branch -d branch-name
//删除远程分支
git push origin --delete branch-name
|
网络问题,可以通过解配置http代理来解决。
1
2
| git config --global --unset http.proxy
git config --global --unset https.proxy
|
1
| git pull --rebase origin branch-name
|
没有权限造成的,打开.git文件夹中的config文件,在url的github前面加上你的用户名,原来为url=https://github.com/your-repository,现在修改为url=https://your-username@github.com/your-repository。
如果filemode是false的话也要设置为true。

重新使用命令git remote add origin ssh-link-of-remote-repository,虽然会显示remote origin already exists,但是执行完该命令之后再使用git pull就没有问题了。
注意检查pull的分支名字是否有错,该分支是否存在,如果不存在先使用命令创建分支。
1
| git branch -M branch-name
|
如果已经进行过remote add添加远程库,则之后只需要进行简单的pull/push操作就可以了。
1
| git pull origin branch-name
|