Guide
git config
配置user.name
user.email
代码提交时,如果不希望使用global的用户,可以为每个项目单独配置用户名和提交邮箱
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| git config --global user.name "username" git config --global user.email "[email protected]"
git config --global --unset user.name git config --global --unset user.email
git config user.name "username" git config user.email "[email protected]"
git config --unset user.name git config --unset user.email
git config --global --list
git config --global user.name git config --global user.email
git config --global --list
git config user.name git config user.email
|
git basic workflow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| git clone https://github.com/kezunlin/demo.git git remote -v git add . git commit -am "init repo" git push origin master
git init . git remote rm origin git remote add origin https://github.com/kezunlin/demo.git git remote -v git pull origin master
git add . git commit -am "init repo" git push origin master
|
git branch workflow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
cd demo git checkout -b newfeature
touch main.cpp
git ls-files
git add . git commit -am 'update in newfeature branch'
git checkout master git pull origin master
git checkout newfeature git merge master
output Already up-to-date! Merge made by the 'recursive' strategy.
git add . git commit -am 'fix some conflicts'
git push -u origin newfeature
|
git tag
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| git tag -a V1.2 -m 'release 1.2'
git tag
git show V1.2
git push origin V1.2 git push origin --tags
git tag -d V1.2 git push origin :refs/tags/V1.2
git fetch origin tag V1.2 ```
```bash
ssh-keygen -t rsa -C "[email protected]" Generating public/private rsa key pair. Enter file in which to save the key (/home/kezunlin/.ssh/id_rsa): id_rsa_kezunlin1
ssh-keygen -t rsa -C "[email protected]" Generating public/private rsa key pair. Enter file in which to save the key (/home/kezunlin/.ssh/id_rsa): id_rsa_kezunlin2
ssh-add ~/.ssh/id_rsa_kezunlin1 ssh-add ~/.ssh/id_rsa_kezunlin2
|
edit config
edit ~/.ssh/config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
Host github.com User git Hostname github.com IdentityFile ~/.ssh/id_rsa
Host kezunlin1.github.com User kezunlin1 Hostname github.com IdentityFile ~/.ssh/id_rsa_kezunlin1
Host kezunlin2.github.com User kezunlin2 Hostname github.com IdentityFile ~/.ssh/id_rsa_kezunlin2
|
upload public keys
- 将id_rsa_kezunlin1.pub添加到kezunlin1的github账号中
- 将id_rsa_kezunlin2.pub添加到kezunlin2的github账号中
test ssh
clone repo
1 2 3 4 5 6 7 8 9 10 11
|
git clone [email protected]:kezunlin1/demo.git git clone [email protected]:kezunlin2/demo.git
Cloning into 'demo'... ERROR: Repository not found. fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
|
when clone repos we must specify
[email protected]:kezunlin1/demo.git
or
[email protected]:kezunlin2/demo.git
Git LFS
Git LFS lets you store files up to 2 GB in size instead of normal 50 MB.
install
download git-lfs-linux-amd64-v2.7.2.tar.gz
from git lfs
1 2 3 4
| tar -xzvf git-lfs-linux-amd64-v2.7.2.tar.gz chmod +x install.sh sudo ./install.sh
|
usage
To get started with Git LFS, the following commands can be used.
Setup Git LFS on your system. You only have to do this once per repository per machine:
git lfs install
Choose the type of files you want to track, for examples all ISO images, with git lfs track:
git lfs track “*.iso”
The above stores this information in gitattributes(5) files, so
that file need to be added to the repository:
git add .gitattributes
Commit, push and work with the files normally:
git add file.iso
git commit -m “Add disk image”
git push
issue the commands
>git lfs install
Updated git hooks.
Git LFS initialized.
>git lfs track "*.pdf"
# generate .gitattributes file
>cat .gitattributes
*.pdf filter=lfs diff=lfs merge=lfs -text
>git add .gitattributes
>git add file.pdf
>git commit -m "Add pdf file"
>git push
Reference
History
- 20190313: created.
- 20191127: add multiple workflow