1. Configuration
1. After the installation is complete, configure the machine information:
$ git config --global user.name "github username"
$ git config --global user.email "[email protected]"
2. Configure ssh key
(1) Create ssh key locally
ssh-keygen -t rsa -C "[email protected]"
Just keep pressing Enter and it will be ok.
(2) Add the ssh public key to the github account
a. Check id_rsa.pub under the ~/.ssh path
cd ~/.ssh
cat ./id_rsa.pub
b. Copy the content to the ssh public key of github
github中的 Settings -> SSH and GPC keys -> New SSH key
2. Build a local git library
Create a project directory and initialize the warehouse in this path:
$ git init
3. Warehouse file operations
1. Add files to the warehouse
$ git add test.txt
2. Submit files to the warehouse
-m is followed by submission instructions
$ git commit -m "write comment here"
3. Version management
(1) Version rollback
Roll back to the previous version (the previous version is HEAD^^)
$ git reset --hard HEAD^
(2) View historical versions
$ git reflog
4. Upload the code to github
1. Establish a link between the local warehouse and the remote warehouse
$ git remote add origin [email protected]:Petal9999/cidiProject.git
2. Upload files to the remote warehouse
(1) push code
$ git push origin master
(2) After execution in the terminal, you need to enter the user name and password:
Username for 'https://github.com': xxxxxxx
Password for 'https://[email protected]':
The username is github username and the password is token
Get it through github's Settings -> Developers settings -> Personal access tokens -> Generate new token
5. Download github code
1、git pull
Suitable for pulling down code from authorized repositories, regardless of local availability
$ git pull orgin master
2、git clone
Suitable for downloading unauthorized code