git的基础操作

1、初始化

git init

  

2、添加本地所有代码

git add .

  

3、提交代码描述

git commit -m '增加新的功能’

  

4、添加远程仓库

git remote add origin git@github.com:xxxx/xxx.git

  

5、初始化推送

git push -u origin master

  

6、提交到主分支

git push origin master

  

7、创建分支

git checkout -b  <branchname>  # -build

  

8、查看分支

git branch   

  

9、提交到缓存区

git add .

  

10、提交到分支

git push origin <barnchname>

  

11、删除分支

git checkout -d  <branchname>   #-delete
git branch -d <branchname>      #-delete

  

12、切换回主分支

git checkout master

  

13、合并到主分支

git merge

  

 

代码提交和同步代码

  • 第1步: 工作区与仓库保持一致
  • 第2步: 文件增删改,变为已修改状态
  • 第3步: git add ,变为已暂存状态
git status
git add --all # 当前项目下的所有更改
git add .  # 当前目录下的所有更改
git add xx/xx.py xx/xx2.py  # 添加某几个文件

   

  • 第4步: git commit,变为已提交状态
    git commit -m"<这里写commit的描述>"
    • 第5步: git push,变为已推送状态
      git push -u origin master # 第一次需要关联上
      git push # 之后再推送就不用指明应该推送的远程分支了
      git branch # 可以查看本地仓库的分支
      git branch -a # 可以查看本地仓库和本地远程仓库(远程仓库的本地镜像)的所有分支

      在某个分支下,常用的操作如下:

      git status
      git add -a
      git status
      git commit -m 'xxx'
      git pull --rebase
      git push origin xxbranch

       

 

转载自https://zhuanlan.zhihu.com/p/445130825 编辑于 2021-12-14 13:06
转载自 https://blog.csdn.net/weixin_45611297/article/details/124365343
 
posted @ 2022-08-21 11:25  留下的枇杷  阅读(32)  评论(0编辑  收藏  举报