Git Bush初始化本地仓库并推送到GitLab远程仓库

  • 记录一次建立远程仓库和提交本地本地老项目的过程
# 1. 初始化本地 Git 仓库
git init

# 2. 或添加所有文件
git add .

# 3. 提交到本地仓库
git commit -m "Initial commit"

# 4. 在GitLab平台创建仓库

# 5. 添加远程仓库地址
git remote add origin <远程仓库URL>

# 6. 查看远程仓库信息
git remote -v
# origin  http://172.27.xx.xx/xx/xx/xx.git (fetch)
# origin  http://172.27.xx.xx/xx/xx/xx.git (push)

# 7. 先拉取远程仓库的内容(允许不相关历史)
git pull origin main --allow-unrelated-histories

# 8. 分支合并界面
# Merge branch 'main' of http://172.27.xx.xx/xx/xx/xx
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
# 然后按 Esc 键退出编辑模式
# 输入 :wq 然后按 Enter 保存并退出

# 9. 推送
git push -u origin main   # 推送
posted @ 2026-02-05 13:56  小菜刀小飞刀  阅读(32)  评论(0)    收藏  举报
//右下角目录