ubuntu16.04 git的配置
git的命令
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Forward-port local commits to the updated upstream head
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
ubuntu16.04 git 卸载
apt-get remove git
git 的安装
- 安装git,在终端输入,双引号填写你自己的用户名
git config --global user.name "your name"
- 配置git,在终端输入
git config --global user.email "your email
- 创建公钥,写上自己的email
ssh-keygen -C "your email" -t rsa
4.在github添加SSH key。
将目录下的.ssh/id_rsa.pub里的内容全部复制。登录github网站,在settings里选择SSH and GPG keys
在title中为本次添加的key取一个名字,将前面粘贴的内容复制到下面的框中。
点击Add SSH key。
- 将key加入到ssh-agent,在终端输入
ssh-add ~/.ssh/id_rsa
- 测试根据自己的需求测试网站可以是码云的,也可以是github的,我这里配置的是码运。
ssh -T git@gitee.com
或则
ssh -T git@github.com
输入以下内容就表示设置成功了。
gitee上传代码
- 进行本地向gitee(码云)上传代码,大致命名如下:
git init git add . git commit -m "first commit" git remote add origin git@gitee.com:b/T.git git pull origin master
- 操作的具体步骤
test@hello:~/test/repos$ cd test/ test@hello:~/test/repos/test$ ls origin_ctg test@hello:~/test/repos/test$ git init Initialized empty Git repository in /home/yeee/test/repos/test/.git/ test@hello:~/test/repos/test$ git add origin_ctg/ test@hello:~/test/repos/test$ git commit -m "first commit" [master (root-commit) e12b13c] first commit 5 files changed, 280 insertions(+) create mode 100644 origin_ctg/.idea/modules.xml create mode 100644 origin_ctg/.idea/origin_ctg.iml create mode 100644 origin_ctg/.idea/vcs.xml create mode 100644 origin_ctg/.idea/workspace.xml create mode 160000 origin_ctg/MCTG test@hello:~/test/repos/test$ git remote add origin git@gitee.com:b/T.git test@hello:~/test/repos/test$ git pull origin master warning: no common commits remote: Enumerating objects: 4, done. remote: Counting objects: 100% (4/4), done. remote: Compressing objects: 100% (4/4), done. remote: Total 4 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (4/4), done. From gitee.com:yeee/test * branch master -> FETCH_HEAD * [new branch] master -> origin/master Merge made by the 'recursive' strategy. README.en.md | 36 ++++++++++++++++++++++++++++++++++++ README.md | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 README.en.md create mode 100644 README.md test@hello:~/test/repos/test$ git push origin master Counting objects: 10, done. Delta compression using up to 48 threads. Compressing objects: 100% (9/9), done. Writing objects: 100% (10/10), 3.87 KiB | 0 bytes/s, done. Total 10 (delta 0), reused 0 (delta 0) remote: Powered By Gitee.com To git@gitee.com:yeee/test.git 839e8ea..ad9975b master -> master
遇到问题
- 执行
git pull origin master
跳出了Nano编辑器如下图:解决方案是这个是使用nano进行编辑提交的页面,退出方法为:
Ctrl + X然后输入y再然后回车,就可以退出了
如果你想把默认编辑器换成别的:
方法一、在GIT配置中设置
core.editor: git config --global core.editor "vim"
方法二、编辑~/.gitconfig文件。在core中添加editor = vim。如此以后在使用git的时候就自动使用vim作为编辑器
2.fatal: remote origin already exists.
参考链接:fatal: remote origin already exists.
在当我们输入git remote add origin https://gitee.com/(github/码云账号)/(github/码云项目名).git
就会报如下的错
fatal: remote origin already exists.
翻译过来就是:致命:远程来源已经存在
此时,我们可以先 git remote -v 查看远程库信息:
可以看到,本地库已经关联了origin的远程库,并且,该远程库指向GitHub。
解决办法如下:
1、先输入$ git remote rm origin(删除关联的origin的远程库)
2、再输入$ git remote add origin git@github.com:(github名)/(git项目名).git 就不会报错了!
3、如果输入$ git remote rm origin 还是报错的话,error: Could not remove config section ‘remote.origin’. 我们需要修改gitconfig文件的内容
4、找到你的github的安装路径,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc
5、找到一个名为gitconfig的文件,打开它把里面的[remote “origin”]那一行删掉就好了!
记一次我关联远程库遇到的错误
用了上面的办法我就解决了( 希望能对看到的人有所帮助 )
心得
- git中仓库与本地中git init的本地文件夹,是一 一对应的。