Git basic tutorial and common questions! You must understand at a glance!
Lead: Git
Road - Git command
Author: become excellent white
hobbies: American some ice!
Note: If you encounter something you don’t understand halfway, you can directly comment and leave a message, and you will immediately answer questions! Say nothing!
table of Contents
- Related Links
- Git several areas
- Basic usage
- common problem
- When .gitignore fails
- Need to switch users
- If there is no upstream branch
- View all branches
- Delete remote branch
- Delete local branch
- Associate github repository
- If the remote branch exists
- Update the latest content of master on the branch
- Upload local files to git
- If any files are not tracked
- Branch ahead
Related Links
Git several areas
- Work area (
workspace
) - Temporary storage area (
index
) - Local warehouse (
local repository
) - Remote warehouse (
remote repository
)
Basic usage
# 初始化git
$ git init
# 克隆项目到本地
$ git clone xx(https/ssh)
# 提交文件到缓存区
$ git add .
# 提交到本地仓库
$ git commit -m ‘提交信息’
# 推送到远程的分支master
$ git push -u origin branch
common problem
When .gitignore fails
# 清除缓存区里面的所有文件,包括了.gitignore
$ git rm -r --cached .
Need to switch users
# 查看全局配置
$ git config —list
# 配置全局变量,切换用户
$ git config —global user.name “xx”
$ git config —global user.email “xx”
If there is no upstream branch
$ git push --set-upstream origin xx(branch)
View all branches
$ git branch
Delete remote branch
$ git push origin —delete xx(branch)
Delete local branch
$ git branch -d xx(branch)
Associate github repository
$ git remote add origin xx(git url)
If the remote branch exists
$ git remote rm origin
Update the latest content of master on the branch
$ git pull --rebase origin master
Upload local files to git
$ git add .
$ git commit -m ‘’
$ git remote add origin xx(git地址)
$ git push -u origin master
# 若遇到地址本身有文件,发送冲突
$ git pull —rebase origin master
If any files are not tracked
# 查看未跟踪文件
$ git status
# 添加跟踪
$ git add xx(文件/文件夹)
Branch ahead
Problem: Your branch is up to date with 'origin/feat/crh
Solve:
# checkout if exist error
$ git status
# create new branch
$ git checkout -b feat/xx
# add&commit&push
# change branch&merge
$ git checkout master
$ git merge feat/xx