一、在github上新建一个空项目
登录github 账户
点击右上角“+” ——> "New repository"
输入仓库名称
不要初始化README、.gitignore或license (保持空仓库)
点击创建“create repository”
二、找到包含项目的文件夹右击选择 Git Bash Here
git init 初始化本地仓库
touch .gitignore 创建忽略文件
touch README.md
git add . 添加所有文件到暂存区
git commit -m "Initial commit" // 提交更改 只是在本地仓库执行
git remote add origin https://github.com/woshiyabg2345/youproject.git // 添加远程仓库地址
git push -u origin main (需要上传的远程仓库的分支名称 git branch -r 查询)
.gitignore 文件内容
# Prerequisites
*.d# Compiled Object files
*.slo
*.lo
*.o
*.obj# Precompiled Headers
*.gch
*.pch# Compiled Dynamic libraries
*.so
*.dylib
*.dll# Fortran module files
*.mod
*.smod# Compiled Static libraries
*.lai
*.la
*.a
*.lib# Executables
*.exe
*.out
*.app
# Directories
build/
git 命令
git remote add origin <仓库URL> 添加 远程仓库urlgit push -u origin master //
origin
:默认的远程仓库名称master
:分支名称(GitHub现在默认使用main)-u
:设置上游(upstream)的缩写 之后 可以直接使用git push 不需要写分支名称git branch -r 远程仓库的分支名称
git branch 本地仓库的分支名称
git pull origin master