All cases:
Configure git username mail
Simply download a warehouse
Pull the update of the remote warehouse to the local warehouse (does not affect the local submission)
Upload local modifications to the remote warehouse
Upload local changes to the remote warehouse and make the local and remote consistent
Create a new warehouse and initialize with local code
I don’t want to sync certain files/folders
Create a temporary branch from the master to make changes, and then merge to the master branch
Delete all historical records of the warehouse, and only keep the current file
Modify the submission information of the previous n commits
Configure git username mail
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Simply download a warehouse
The most commonly used method
git clone https://github.com/xxx/xxx.git
The project is too big, I want to download it quickly, no history is needed
git clone --depth 1 https://github.com/xxx/xxx.git
Want to quickly download non-master branches
git clone --depth 1 https://github.com/xxx/xxx.git
cd xxx
git remote set-branches origin 'remote_branch_name'
git fetch --depth 1 origin remote_branch_name
git checkout remote_branch_name
Pull the update of the remote warehouse to the local warehouse (does not affect the local submission)
git pull origin master
Upload local modifications to the remote warehouse
git add .
git commit -m "提交说明"
git push origin master
Upload local changes to the remote warehouse and make the local and remote consistent
git add .
git commit -m "提交说明"
git pull origin master
git push origin master
Create a new warehouse and initialize with local code
First go to github or other git sites to create a new warehouse and get the new warehouse address, similar to https://github.com/xxx/xxx.git
git init
git add -A
git commit -m "初始化代码"
git remote add origin https://github.com/xxx/xxx.git
git push -u origin master
I don’t want to sync certain files/folders
Under the new root of the repository .gitignore
file
in which you want to ignore the written content, support files, folders, wildcards
target/
.idea/
*.log
somefile.txt
Create a temporary branch from the master to make changes, and then merge to the master branch
- Create a temporary branch
git checkout master
git pull origin master
git checkout -b tmp
git push origin tmp # 在远程也创建临时分支
git branch --set-upstream-to=origin/tmp
git pull origin tmp
- Modify the code in the way you like, you can submit the code in the process
git add .
git commit -m "提交说明"
git push origin tmp
- Finally merge branch tmp to master, then delete tmp
git checkout master
git merge tmp
git push origin master
git branch -d tmp
git push origin --delete tmp
Delete all historical records of the warehouse, and only keep the current file
git checkout --orphan lastest # 从0新建分支
git add -A # 添加所有当前文件到分支
git commit -m "init信息"
git branch -D master # 删除master分支
git branch -m master # 重命名当前分支为master
git push -f origin master # 强制提交到远程
Modify the submission information of the previous n commits
git rebase -i HEAD~n # 这里查看最近n次commit提交信息
# 然后进入编辑模式,将需要修改的commit那一行的pick修改为edit,保存退出
git commit --amend # 这会进入上面修改对应的commit提交信息
git rebase --continue # 回到正常状态