本地使用git托管代码(win10)

本文介绍了在Windows 10上使用git托管本地代码的步骤,包括安装git-for-windows,编写工程文件,创建本地git仓库,进行git配置(全局或局部),以及如何将文件添加并提交到仓库。在提交前别忘了编写.gitignore文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 安装git-for-windows
2. 编写工程文件
  • 编程一个工程test\,注意要写.gitignore文件

    D:\develop\test
    λ touch test.py
    
    D:\develop\test
    λ touch .gitignore
    
    D:\develop\test
    λ touch README.md
3. 创建空的git仓库
  • 在本地创建一个空仓库,此时这个仓库是空的,什么文件都没有

    D:\develop\test
    λ git init
    Initialized empty Git repository in D:/develop/test/.git/
4. 本地配置git
  • 假如只有一个远程git托管账号,则可以使用全局配置 --gloabl ,即所有git仓库的配置(如下是告诉git即将提交的文件和代码是哪个人写的)

    D:\develop\test
    λ git config --global user.name "your_github_name"
    
    D:\develop\test
    λ git config --global user.email "your_github_email"
    
    # 查看git的全局配置:
    
    D:\develop\test
    λ git config -l
  • 假如有两个远程git托管账号,例如gitlab和github,可以使用局部配置--local,即当前git仓库的配置

    D:\develop\test
    λ git config --global user.name "your_github_name"
    
    D:\develop\test
    λ git config --global user.email "your_github_email"
    
    # 查看git的局部配置
    
    D:\develop\test
    λ git config --local -l
5. 往仓库中添加(add)文件并提交(commit)
  • 注意:commit整个工程之前,务必先写好.gitignore

    D:\develop\test (master -> origin)
    λ git add *
    
    D:\develop\test (master -> origin)
    λ git commit -m "your commit messsage"
    
    [master (root-commit) 621b68f] your commit messsage
     3 files changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 .gitignore
     create mode 100644 README.md
     create mode 100644 test.py
  • 至此,在本地已可以使用git仓库来管理工程文件的代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值