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
### 如何将本地Git项目推送到远程仓库 GitHub 将本地Git项目推送到远程仓库GitHub的过程可以分为几个关键步骤,以下是对这一过程的详细说明: 1. **初始化本地仓库** 在本地创建一个文件夹作为项目的根目录,并通过 `git init` 将其初始化为Git仓库[^1]。 ```bash git init ``` 2. **添加和提交项目文件** 将项目文件添加到仓库中,并通过 `git commit` 提交更改[^1]。 ```bash git add . git commit -m "初始化项目" ``` 3. **创建远程仓库** 登录GitHub账户,创建一个新的远程仓库。注意,在创建时可以选择不添加README文件,以便后续推送时不发生冲突[^2]。 4. **关联本地仓库远程仓库** 使用 `git remote add origin` 命令将本地仓库远程仓库进行关联[^1]。 ```bash git remote add origin https://github.com/用户名/仓库名.git ``` 5. **推送代码到远程仓库** 使用 `git push` 命令将本地仓库的内容推送到远程仓库。如果是首次推送,需要指定分支并使用 `-u` 参数设置上游分支[^1]。 ```bash git push -u origin master ``` 如果远程仓库不允许直接推送到 `master` 分支,可以切换到其他分支(如 `dev`)再推送[^5]。 ```bash git checkout -b dev git push -u origin dev ``` 6. **处理身份验证问题** 如果遇到权限问题,可以通过配置SSH密钥或使用带有Token的链接来解决[^3]。例如: ```bash git remote set-url origin https://token@github.com/用户名/仓库名.git ``` 7. **同步远程仓库信息(可选)** 如果需要拉取远程仓库的最新内容并与本地合并,可以使用 `git pull` 命令[^4]。 ```bash git pull origin master --allow-unrelated-histories ``` 8. **检查配置(可选)** 为了确保用户名和邮箱与GitHub一致,可以检查当前Git配置[^3]: ```bash git config -l --show-origin ``` 如果需要修改,可以执行以下命令: ```bash git config user.name "你的用户名" git config user.email "你的邮箱" ``` 通过以上步骤,可以成功将本地Git项目推送到远程仓库GitHub。 ### 注意事项 - 如果远程仓库已经存在文件,可能会导致推送失败,此时需要先拉取远程内容并解决冲突。 - 推送时如果遇到权限问题,建议检查SSH密钥配置或使用Token认证。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值