残灯飞雪 的博客地带

生活依旧美好,人生还需前行!

0%

Git常见问题分享

点击此处,浏览效果更好

版权声明:本文为博主 @残灯飞雪
的原创文章,欢迎转载,传播知识。著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明作者和出处并留言告知博主,方便文章有误改正之后能找到原文!!!
原文链接:blog.mintools.cn

1. Github常用的命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# git本地仓库初始化
$ git init Initialized empty Git repository in /d/toolsWorkspaces/Demo/.git/
# 将本地项目的所有文件添加到暂存区中
$ git add .
# 将暂存区的文件提交到git本地仓库
$ git commit -m "注释语句"
# 将本地仓库关联到Github
$ git remote add origin Github仓库项目https网址
# 查看当前是否在master
$ git check master
# 将代码由本地仓库上传到Github远程仓库
$ git push -u origin master
# 撤销修改
$ git checkout -- file
# 删除文件
$ git rm file
# 查看状态
$ git status
# 添加记录
$ git add file 或 $ git add .
# 添加描述
$ git commit -m "miao shu nei rong"
# 同步数据
$ git pull
# 提交数据
$ git push origin name
# 查看分支
$ git branch
# 创建分支
$ git branch name
# 切换分支
$ git checkout name
# 创建+切换分支
$ git checkout -b name
# 合并某分支到当前分支
$ git merge name
# 删除分支
$ git branch -d name
# 删除远程分支
$ git push origin :name

2. 设置Git身份信息

在安装完Git后,第一步就是设置Git身份信息:

1
2
$ git config --global user.name "myusername"    #用户名
$ git config --global user.email "myemail" #邮箱

如要查看用户:

1
$ git config --list

【可能遇到的问题】
配置SSH keys密钥后,ssh -T git@github.com检验SSH已经配置好,返回结果如下:

1
Hi xxxxxx! You've successfully authenticated, but GitHub does not provide shell access.

但是,当上传本地仓库代码到远程仓库时,总是失败,提示如下情况时,则是要做本步骤提到的设置Git身份信息:

1
2
3
4
5
6
7
Unable to auto-detect email address (got 'Arreane@Arreane-PC.(none)')
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository

3. 给Git命令起别名:

别名用起来很简短顺手,如把git status -> git st,使用如下命令:

1
$ git config --global alias.st status

版权声明:本文为博主 @残灯飞雪
的原创文章,欢迎转载,传播知识。著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明作者和出处并留言告知博主,方便文章有误改正之后能找到原文!!!
原文链接:blog.mintools.cn

坚持原创技术分享,您的支持将鼓励我继续创作!