传代码到GitHub上面的

假设之前的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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值