Git常用指令

Git常用指令

fanz Lv3

1、Git init (在本地工程目录下),生成.git 文件夹

1
Git init

2、上传修改的文件

1
git add *

(*可替换成具体要上传的文件名,*表示提交所有有变化的文件)

3、添加上传文件的描述

1
git commit -m "test" 

(”test“为分支名)

4、(创建分支)

1
git branch test

5、(切换分支)

1
git checkout test

6、与远程分支相关联

1
git remote add origin https://github.com/yangxiaoyan20/BowlingScore.git

(”BowlingScore“ 为工程名)

单独下载某一个分支的代码

1
2
git clone -b   分支名   项目地址
//git clone -b wang https://e.coding.net/latitude/ideo/ideo.git

7、(将分支上传)

1
git push origin test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#上传者姓名(设置一次即可)
git config --global user.name "xl"
#上传者邮箱 (设置一次即可)
git config --global user.email "[email protected]"

#添加远程仓库地址(就是服务器地址) --第一次时使用
git remote add origin https://gitcode.net/xiaolong1126626497/bmp_code.git
git remote add 地址变量名 url

#修改远程仓库地址(就是服务器地址),如果之前已经设置过其他地址,就使用修改命令
git remote set-url origin https://gitcode.net/xiaolong1126626497/bmp_code.git
git remote set-url 地址变量名 新url

#添加所有文件
git add .
#写上修改说明
git commit -m "添加test.c"
#上传至仓库
git push -u origin master
git push -u origin 分支名

8、完整命令流程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#删除原来的git文件夹
rm -rf .git/
#新建git文件夹,初始化
git init
#添加远程仓库地址和地址变量origin,将url赋值给origin --第一次使用
git remote add origin https://e.coding.net/latitude/ideo/ideo.git
//#修改地址变量名的url信息 --第二次使用
//git remote set-url origin https://e.coding.net/latitude/ideo/ideo.git
#添加本地所有的文件
git add .
#提交所有文件,赋上提交的信息
git commit -m “Commit message”

//#创建新的test分支
//git branch test
//git branch 分支名
//#选择刚才创建的test分支
//git checkout test
//git checkout 分支名

#提交到origin的master分支
git push -f origin master
#提交到origin的test分支
git push -f origin test

9、Git clone (使用 -b 指定分支)

1
git clone -b dev_jk http://10.1.1.11/service/tmall-service.git
  • 标题: Git常用指令
  • 作者: fanz
  • 创建于 : 2025-02-24 14:49:06
  • 更新于 : 2025-02-24 14:52:14
  • 链接: https://redefine.ohevan.com/ss6dlu/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。