假设之前的SSH都配置好了,下载了git!
1、仓库的初始化
选择你代码所在的文件夹,鼠标右键,“Git Bash Here”,进入。
然后输入命令:
git init
创建本地git
然后给仓库添加远程地址,输入命令:
git remote add origin
git@github.com:yourName/yourRepo.git yourName是你的用户名,yourRepo是你的仓库名。例如我的就是GooZy/Codes.git
接着输入命令:
git pull –rebase origin master
将github上仓库的文件和本地文件同步。
2、上传代码
输入命令:
git add acm.cpp
可以选择需要上传的单文件,或者git add -A,将当前目录下的所有文件上传。
第一步之后,
git commit -m “XXX”
上传文件,双引号内为文件的一些描述,多文件会统一使用这个描述。
最后,输入命令:
git push -u origin master
即可将文件将文件同步到github上了。之后想要上传、更新,重复第五步即可。
error: failed to push some refs to ‘git@github.com:RoniZeng/algorithm.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.
附:
第五步中,如果选择-A则把所有文件都上传,此时一些.exe、.o文件都会被上传,这时我们可以用git的gitignore方法。具体用法如下:
首先右键仓库,Git Bash Here进入仓库。输入 touch .gitignore,就会生成一个名为”.gitignore”的文件。
然后自己在文件中找到该文件,点击编辑,输入要屏蔽的文件类型即可。例如输入:
*.o
*.exe