步骤一

# 配置git的全局用户名和密码
git config --global user.name "qiuyedx" # qiuyedx换为自己定的用户名
git config --global user.email "qiuyedx@foxmail.com" # qiuyedx@foxmail.com为用户邮箱(最好和github上绑定的邮箱一样)

# 生成ssh密钥
ssh-keygen -t rsa -C "qiuyedx@foxmail.com"
# 之后一直回车即可

步骤二

将~/.ssh/id_rsa.pub中的内容复制到https://github.com/settings/ssh/new 

# 创建新仓库 https://github.com/new

# git无密码操作 (暂时可略)
# 配置token
参照https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

步骤三

# XXX处替换为想clone的仓库URL(若用https协议则需要用户名密码, ssh不用)
git clone XXX
# ABC替换为仓库名, 进入仓库根目录
cd ABC

# 新仓库的主分支名称是main, 老仓库是master, 自己在仓库分支中看清楚
git push -u origin main

常用指令

git helper -a // 查看全部git子命令

git pull // 从远程 Git 仓库拉取变更并合并到本地 Git 仓库
git add . // 将所有文件提交到暂存区
git commit -m "提交的备注信息"  // 提交到仓库 若已经有若干文件放入仓库,再次提交可以不用git add和git commit -m "备注信息" 这2步
git push -u origin main // 上传

git push -- force // 强制推送(慎用,除非你认为其他冲突等可以丢弃 或者不是很重要)

git init // 初始化 在工作路径上创建主分支
git clone 地址 // 克隆远程仓库
git clone -b 分支名 地址 // 克隆分支的代码到本地
git status // 查看状态
git add 文件名 // 将某个文件存入暂存区
git checkout -- file // 撤销工作区的修改 例如git checkout -- readMe.txt 将本次readMe.txt在工作区的修改撤销掉
git add b c //把b和c存入暂存区
git add -p 文件名 // 一个文件分多次提交
git stash -u -k // 提交部分文件内容 到仓库 例如本地有3个文件 a b c 只想提交a b到远程仓库 git add a b 然后 git stash -u -k 再然后git commit -m "备注信息" 然后再push push之后 git stash pop 把之前放入堆栈的c拿出来 继续下一波操作
git commit -am "备注信息" // 将内容放至仓库 也可用git commit -a -m "备注信息"
* git commit中的备注信息尽量完善 养成良好提交习惯 例如 git commit -m "变更(范围):变更的内容"

......

指令概览

  • git init:初始化一个新的 Git 仓库。
  • git clone:从远程 Git 仓库克隆一个本地仓库。
  • git add:将文件添加到 Git 仓库的暂存区。
  • git commit:将暂存区的文件提交到 Git 仓库。
  • git status:查看 Git 仓库的当前状态。
  • git log:查看 Git 仓库的提交日志。
  • git branch:查看、创建、删除 Git 分支。
  • git checkout:切换 Git 分支或恢复文件到某个版本。
  • git merge:将两个 Git 分支合并。
  • git push:将本地 Git 仓库的变更推送到远程 Git 仓库。
  • git pull:从远程 Git 仓库拉取变更并合并到本地 Git 仓库。
  • git fetch:从远程 Git 仓库拉取变更到本地 Git 仓库,但不合并。
  • git remote:管理远程 Git 仓库。
  • git tag:为 Git 仓库中的某个版本打标签。
  • git reset:撤销 Git 仓库中的某个版本。

A Student on the way to full stack of Web3.