git常用命令

1、初始化仓库

1.1、Git 全局设置

git config --global user.name "wanghx"
git config --global user.email "9016814@qq.com"

1.2、创建 git 仓库

mkdir TjHisNet6Api
cd TjHisNet6Api
git init 
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin https://gitee.com/his7/tj-his-net6-api.git
                      
git push -u origin "master"

1.3、已有仓库

cd existing_git_repo
git remote add origin https://gitee.com/his7/tj-his-net6-api.git
git push -u origin "master"

1.4、常用命令

# 添加当前目录的所有文件到暂存区
$ git add .

# 显示有变更的文件
$ git status

# 提交暂存区到仓库区
$ git commit -m "项目初始化"

# 显示当前分支的版本历史
$ git log

# 提交指定tag
$ git push

# 拉取
git pull --rebase origin master

1.5、常用命令托管到码云上

  • 注册并激活码云账号( 注册页面地址:https://gitee.com/signup

  • 生成并配置 SSH 公钥,在C:\Users\Administrator.ssh(没有的话,用ssh-keygen -t ed25519 -C "9016814@qq.com" 三次回车生成)

  • ssh -t git@gitee.com 监测公钥是否配置成功

    Administrator@wanghx MINGW64 /d/vsdemo/vs2022/uni-app/uni-app-shop (master)
    $ ssh -t git@gitee.com
    The authenticity of host 'gitee.com (212.64.63.215)' can't be established.
    ED25519 key fingerprint is SHA256:+ULzij2u99B9eWYFTw1Q4ErYG/aepHLbu96PAUCoV88.
    This key is not known by any other names
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    Warning: Permanently added 'gitee.com' (ED25519) to the list of known hosts.
    Hi wanghx! You've successfully authenticated, but GITEE.COM does not provide shell access.
    Connection to gitee.com closed.
    
    Administrator@wanghx MINGW64 /d/vsdemo/vs2022/uni-app/uni-app-shop (master)
    
    
  • 创建空白的码云仓库,切换为ssh方式,执行以下两个语句,将源码推送到仓库

    git remote add origin git@gitee.com:his7/uni-app-shop.git
    git push -u origin "master"
    
posted @ 2022-10-24 20:49  his365  阅读(61)  评论(0)    收藏  举报