1、弹出git 操作台
项目内的根目录 右键 git bash here
2、输入用户名(并不是github的)
输入 git config --global user.name "wlj"
3、 输入邮箱
输入 git config --global user.email "870182492@qq.com"
4、初始化git
输入 git init

5、把项目的所有文件添加到git空间
输入 git add .
如果想添加某个特定的文件,只需把.换成特定的文件名即可

6、输入提交描述信息
输入 git commit -m "描述你提交哪些内容"


7、将本地的仓库关联到github上
输入 git remote add origin ssh地址
https地址也行

8、上传github之前,要先pull一下
输入 git pull origin master

9、上传代码到github远程仓库
输入 git push -u origin master

10、坐等上传完毕
问题一:



$ git pull origin master
git@gitee.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
解决:
1、生成公钥:ssh-keygen -t rsa -C "870182492@qq.com"
2、三次点击enter键
3、查看公钥:cat ~/.ssh/id_rsa.pub
4、到gitee上或者github上添加公钥
5、添加后,在终端(Terminal)中输入:ssh -T git@gitee.com
看到Welcome to Gitee.com, yourname!则表明成功
问题二:
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
有如下几种解决方法:
1.使用强制push的方法:
$ git push -u origin master -f
这样会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候。
2.push前先将远程repository修改pull下来
$ git pull origin master
$ git push -u origin master
3.若不想merge远程和本地修改,可以先创建新的分支:
$ git branch [name]
然后push
$ git push -u origin [name]
网友评论