Skip to content

初始化非空目录指向远程仓库

How to convert existing non-empty directory into a Git working directory and push files to a remote repository

提示:在git remote add origin使本地仓库指向远程仓库后,需要马上git pull origin main拉取远程提交到本地。在同步到远程最新代码后,再提交本地修改一切就很顺利了。

切换到本地非空目录

bash
cd <localdir>

初始化本地非空目录为git仓库

bash
git init

本地git仓库指向远程仓库

bash
git remote add origin <url>

拉取远程代码到本地

bash
git pull origin main

查看本地分支名称

bash
git branch

重命名本地分支mastermain

bash
git branch -m master main

stage所有本地修复

bash
git add .

提交本地所有stage修改

bash
git commit -m 'message'

推送本地commit到远程仓库

bash
git push origin main