首先创建一个远程仓库,创建完成后添加自己的ssh公钥,公钥生成方法:
$ ssh-keygen -t rsa -C "xxxxx@xxxxx.com" //按3次回车即可,路径等保持默认
$ cat ~/.ssh/id_rsa.pub //查看ssh公钥
$ git config –global core.autocrlf false
初始化仓库前先关闭换行符自动转换,这样在git add时就不会自动转换换行符,而是保留原来的样子,这一步根据自己的需要确定,不是必须的
$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"
配置自己的名字和邮箱
$ git init //初始化仓库
$ git remote add origin https://gitee.com/example/example-01.git //关联到远程仓库
$ git add a.c a.h common.h //添加将需要的文件
$ git commit -m "The First commit."
$ git push -u origin master //首次push加-u,之后再push就不用加-u了
下面是可能出现的错误和解决方法:
错误:
error: src refspec master does not match any. error: failed to push some refs to 'git@github.com:hahaha/ftpmanage.git'
原因:
本地仓库为空
解决方法:
$ git add *
$ git commit -m "init files"
错误:
$ git push -u origin master Warning: Permanently added the RSA host key for IP address 'xx.xx.xxx.xxx' to the list of known hosts. To git@github.com:hahaha/ftpmanage.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'git@github.com:hahahah/ftpmanage.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解决方法:
git pull 之后再 push