git把本地项目push到远程仓库

环境

系统:windows

目录:D:/workspace/idea/spark-test

远程仓库:https://github.com/HanlaoTwo/SparkStudy.git

协议:https

创建版本库
#初始化
git init

Reinitialized existing Git repository in D:/workspace/idea/spark-test/.git/

#用命令git add告诉Git,把文件添加到仓库:
git add *
warning: LF will be replaced by CRLF in src/main/scala/sql/SparkSQLExample.scala.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/compiler.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/encodings.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/misc.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/modules.xml.
...

#提交
git commit -m "all is new"
[master (root-commit) 521cf14] all is new
warning: LF will be replaced by CRLF in .idea/compiler.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/encodings.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/misc.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/modules.xml.
提交到远程仓库
#添加
git remote add origin https://github.com/HanlaoTwo/SparkStudy.git
#报错,已存在
fatal: remote origin already exists.

#删除
git remote rm origin
#再添加
git remote add origin https://github.com/HanlaoTwo/SparkStudy.git

#提交
git push -u origin master
Username for 'https://github.com': hanlaotwo
Password for 'https://hanlaotwo@github.com':
Counting objects: 294, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (279/279), done.
Writing objects:  99% (292/294), 1.10 MiB | 68.00 KiB/s
在 Visual Studio Code (VSCode) 中使用 Git 将本地项目推送到远程仓库通常分为以下几个步骤: 1. **安装Git**: 如果还未安装 Git,你需要先从官方网站下载并安装 Git(https://git-scm.com/downloads)。 2. **初始化本地仓库**: 打开 VSCode,右键点击项目文件夹,选择“Git” > “Initialize Repository”,创建一个新的 .git 文件夹。 3. **配置用户信息**: 在终端或命令提示符中输入 `git config --global user.name` 和 `git config --global user.email` 来设置你的用户名和邮箱。 4. **添加文件到暂存区**: 添加所有要提交的更改到暂存区(staging area),例如: ``` git add . ``` 5. **查看状态**: 查看当前哪些文件被添加了或修改了,用 `git status`。 6. **提交更改**: 输入提交信息描述这次提交的内容,然后执行: ``` git commit -m "your commit message" ``` 7. **连接远程仓库**: 首次连接时,需要生成一个新的 SSH 密钥对,将其添加到 GitHub 或其他服务的SSH密钥管理(如 `ssh-agent`)。然后,在命令行中,复制远程仓库的 URL 并运行: ``` git remote add origin <remote-repo-url> ``` 8. **推送代码**: 最后,将本地分支推送到远程仓库: ``` git push -u origin main ``` `-u` 标志是首次推送时自动跟踪远程主分支。 如果你还没有创建过远程仓库,第一次推送会提示你是否要创建一个新的远程分支。根据提示操作即可。 **相关问题--:** 1. 如何检查我的 Git 是否已经正确设置? 2. 除了 `main` 分支,还有哪些常见的远程分支名称? 3. 如何解决推送失败,因为默认分支与远程不符的问题?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值