初始化操作
全局配置
git config --global user.name "xxx"
git config --global user.email "xxx@xx.com"
创建新仓库
git clone git@gitlab.bl.com:XXX/xxx.git
cd cdpstream
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
推送已存在的文件夹
cd existing_folder
git init
git remote add origin git@gitlab.bl.com:XXX/xxx.git
git add .
git commit -m "Initial commit"
git push -u origin master
注意:在项目中最好先创建.gitignore,其中把开发工具自身等对其它人员无用的配置文件或文件夹忽略
/bak
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**
.idea
*.iml
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
.log
jars
.mvn
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
### VS Code ###
.vscode/
推送已存在Git仓库
cd existing_repo
git remote rename origin old-origin
git remote add origin git@gitlab.bl.com:XXX/xxx.git
git push -u origin --all
git push -u origin --tags
常用操作
可看当前状态
# git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .gitignore
new file: .idea/.gitignore
从stage中删除
git rm --cached <file>
配置
git config命令的–global参数,表示你这台机器上所有的Git仓库都会使用这个配置,也可以对某个仓库指定不同的用户名和Email地址。
查看配置信息
$ git config --list
查看用户名、密码、邮箱
$ git config user.name
$ git config user.password
$ git config user.email
设置
用户名、密码、邮箱
$ git config user.name "sven"
$ git config user.password "xxx"
$ git config user.email "xxx@xxx"
用户名、密码、邮箱
$ git config --global user.name 用户命
$ git config --global user.name freedom
$ git config --global user.password 密码
$ git config --global user.password abc0506abc
$ git config --global user.password 邮箱
$ git config --global user.email "xxx@xxx"
修改用户名、密码、邮箱的配置
$ git config user.name "sven"
修改全局配置用户名、密码、邮箱
$ git config --global user.name "sven"
Command line instructions
You can also upload existing files from your computer using the instructions below.
Git global setup
git config --global user.name "魏山巍"
git config --global user.email "shanwei.wei@bl.com"
Create a new repository
git clone git@gitlab.bl.com:CDP/cdp-elastic.git
cd cdp-elastic
git switch -c main
touch README.md
git add README.md
git commit -m "add README"
git push -u origin main
Push an existing folder
cd existing_folder
git init --initial-branch=main
git remote add origin git@gitlab.bl.com:CDP/cdp-elastic.git
git add .
git commit -m "Initial commit"
git push -u origin main
Push an existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin git@gitlab.bl.com:CDP/cdp-elastic.git
git push -u origin --all
git push -u origin --tags