当前位置:   article > 正文

本地创建Git仓库_本地git创建

本地git创建

在 Windows 下,可以通过以下步骤在本地创建一个 并模拟远程Git 仓库。

1、在命令行中打开模拟远程Git 仓库目标文件夹: 打开命令提示符或 PowerShell。例如:

创建裸仓库(模拟远程仓库):创建一个裸仓库,这将模拟远程仓库的位置。使用以下命令:
git init --bare /path/to/your/remote/repo.git
请确保将 /path/to/your/remote/repo.git 替换为希望存储模拟远程仓库的路径。

如果使用的是网络共享路径,也可以使用:
git remote add origin file:path/to/your/remote/repo.git
请根据实际情况选择适当的方式。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

2、在本地文件夹拉取模拟的远程仓库

cd /path/to/your/local/repo
git clone /path/to/your/remote/repo.git

cd repo      //切换到 .git所在目录
git remote -v   // 这将显示远程仓库信息。

// 使用echo your_text_here > filename.extension 创建一个文件,如
echo content > main.cpp       //content 为文本内容
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

3、推送至远程仓库

git add main.cpp                        // 保存修改
git commit -m "添加到远程"        // "添加到远程"  为修改分支的记录名称,可自行修改
  • 1
  • 2

在这里插入图片描述

git push
  • 1

在这里插入图片描述

4、常用命令

git status        // 查看当前所在分支状态,若存在修改(未保存会显示红色文件名,保存后的显示绿色文件名)

git branch new_branch_name     // 新建分支

git switch branch_name 切换分支

git pull  // 拉取当前的远程分支内容至本地,若远程分支有改动,则会更新本地的代码

// 推送
git add <files>  //保存、   
git commit -m "添加到远程" 
git push     // 将修改内容上传至远程分支
// 保存、添加修改名称及上传用vscode更方便
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号