git初始化
…or create a new repository on the command line
echo "# dingliOBJ" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/tour9566/**.git
git push -u origin main
…or push an existing repository from the command line
git remote add origin https://github.com/tour9566/dingliOBJ.git
git branch -M main
git push -u origin main
git基本
git init // 初始化 在工作路径上创建主分支
git clone git地址 // 克隆远程仓库
git clone -b 分支名 地址 // 克隆分支的代码到本地
git status // 查看状态
git add 文件名 // 将某个文件存入暂存区
git add . // 将所有文件提交到暂存区
git commit -m "提交的备注信息" // 提交到仓库
Git-push和pull分支
查看分支信息:git branch -r
查看所有分支信息:git branch -a
本地推送分支:git push origin branch-name
推送分支前最好先pull分支:git pull origin branch-name
本地创建与远程分支对应的分支:git checkout -b branch-name origin/branch-name
建立本地分支与远程分支关联:git branch --set-upstream-to=origin/branch-name branch-name
git stash
git stash // 把暂存区的内容 暂时放在其他中 使暂存区变空
git stash list // 查看stash了哪些存储
git stash pop // 将stash中的内容恢复到当前目录,将缓存堆栈中的对应stash删除
git stash apply // 将stash中的内容恢复到当前目录,不会将缓存堆栈中的对应stash删除
git stash clear // 删除所有缓存的stash
git branch
git branch 分支名 // 新建分支
git branch // 查看当前所有分支
git checkout 分支名 // 检出分支
git checkout -b 分支名 // 创建并切换分支
git branch -v // 查看分支以及提交hash值和commit信息
git merge 分支名 // 把该分支的内容合并到现有分支上
git branch -d 分支名 // 删除分支
git branch -m 旧分支名 新分支名 // 修改分支名
git branch -M 旧分支名 新分支名 // 修改分支名 M强制修改 若与其他分支有冲突也会创建(慎用)
git branch -r // 列出远程分支(远程所有分支名)
git branch -a // 查看远程分支(列出远程分支以及本地分支名)
常用命令
git init 初始化
git clone 地址 克隆一个地址
git add . 添加文件
git commit “提交文件注解”
git remote add origin https://github.com/xx 与远程仓库管理
git push origin master 提交到远程仓库
git checkout -b dev 创建本地分支
git branch -a 查看分支
git push origin dev:dev 提交到远程仓库
git stash 本地暂时保存