把文件上传到git,但本地还没有这个项目,怎么办?需要新建Git仓库并添加本地项目

本文详细介绍了如何使用Git将本地项目上传到远程仓库的过程,包括初始化仓库、添加文件、提交更改、设置远程仓库、解决常见错误及推送代码到远程仓库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

需要新建Git仓库并添加本地项目

1 新建目录git_dir,把需要上传到git的文件enc.jar复制到这个目录下

2 初始化当前目录作为Git仓库:

git init

3 添加目录下的文件到本地仓库:从工作区提交到暂存区

git add enc.jar  

# git add . 添加当前目录下的所有文件

4 提交staged的文件,从暂存区提交到本地代码仓库

git commit -m "提交enc.jar"

5 使用命令行添加远程仓库的地址。

git remote add origin https://github.com/...../abc.git

6 git pull

  此时可能会报错,提示输入username,password

 输入后,再git pull,可能仍然会报错:

gitThere is no tracking information for the current branch.

Please specify which branch you want to merge with.

See git-pull(1) for details

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> merged0.9.6

是因为本地分支和远程分支没有建立联系  (使用git branch -vv  可以查看本地分支和远程分支的关联关系)  .根据命令行提示只需要执行以下命令即可

git branch --set-upstream-to=origin/master master  ,把远程master分支,关联到本地master分支

# git branch --set-upstream-to=origin/远程分支的名字 本地分支的名字 

再次运行git pull会发现git_dir目录下有很多从远程master分支上下载下来的文件

7 提交文件

 git push origin master ,从本地代码库提交到远程代码库的master分支

 

使用 git branch -a 能看到本地和远程的所有分支。

参考:

https://blog.csdn.net/theonegis/article/details/80115316

https://blog.csdn.net/ming13849012515/article/details/81011632

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

二十六画生的博客

你的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值