上传的远端git可以是gitlab、github、gitee、gitblit或者gitCode等等
以下以GitHub为例说明:
1、登录GitHub网站(账户/密码)
2、创建一个新的空白项目(或者已有的项目)hello-world

分支是master ,这里默认即可。
任务则是将一个srccode的文件夹上传上去,文件夹内容可以很多,这里模拟只是放一个main.cpp

方法一:直接拉一个项目下来,然后再上传
1、在该层级文件夹中右击打开Git Bash Here

2 、获取hello-world项目的远程地址

3、clone该项目到test文件夹下
git clone GitHub - nankeyh/hello-world: Just another repository


4、把需要上传的文件夹放到hello-world项目目录下,同时git上层级进入到hello-world

自动会识别该git的分支为master
5、添加新目录文件到仓库
git add . 或者git add -A
6、然后添加备注
git commit -m "xx"

7、将内容推上远端的仓库
git push


8、如果有更新,则需要先拉取远端,再添加,备注并推送
git pull
git add .
git commit -m "xx"
git push
方法二:本地的文件夹直接生成git仓库,然后上传至远端仓库
1、git配置
在打开的编辑里面依次输入并执行配置信息(主要后面commit需要,否则报错)
git config --global user.name "liehuodadi"
git config --global user.email "dfbazhu@qq.com"
其中"liehuodadi"是用户名,可以填写您的github的用户名,
第二行的"dfbazhu@qq.com"自然是邮箱了,可以填写您的github账号的邮箱,
用户名和邮箱也可以填写别的(只要是用户名和邮箱格式就OK)。
2、生成密钥
输入以下代码,:
ssh-keygen -t rsa -C "dfbazhu@qq.com"
输入上面的命令后一直按3次回车直到出现图形界面即可
3、添加密钥到github
①输入命令,可以看到上一步生成的密钥
cat ~/.ssh/id_rsa.pub
回车后即可看到密钥
②从ssh-rsa开始将密钥复制下来。也可以打开C:\Users\Administrator\.ssh\id_rsa.pub从该文件中复制密钥。
③进入github头像下面的 settings ,点击左侧的"SSH and GPG keys",然后 new SSH key
Title随便填写,key type默认即可,key 里面将上面我们复制的那个本地密钥粘贴到这里,然后点击"Add SSH key"即可。这样我们就有权限对自己在github上的项目进行读写操作了。
4、建立本地仓库并初始化
从该文件夹右键进入git bash here
git init
文件夹里面生成一个名为.git的文件夹,这个文件夹是隐藏的!需要电脑设置显示隐藏文件夹。
5、本地电脑连接github项目
获取hello-world项目的网页地址
git remote add origin GitHub - nankeyh/hello-world: Just another repository
6、同步github项目到本地
git pull origin master
7、将本地项目上传到github对应的项目里面
①添加文件到缓存区
git add .
注意add与"."之间有一个空格。
此时会要求您输入码云的账号和密码,登录即可
②为上传文件添加注释
等待缓存完毕,接着输入命令:
git commit -m "first push"
其中的first push为注释的内容,请自定义填写。
③提交代码到github项目
等待上步完成,继续输入执行命令:
git push origin master