First, you need to register a github account and install and configure git locally to make it available locally.
1. Create a public key (ssh-key)
ssh-keygen -t rsa -C “your email address”
Enter all the way to select the default value and generate a folder ~ / .ssh.
cd ~/.ssh
You can see that the id_rsa.pub file is generated under this folder.
2. Add the public key to Github
Log in to the github account, select and open the settings, select SSH and GPG keys, select New SSH key, fill in the title in Title, and fill in the public key in the id_rsa.pub file in Key.
Note that the content in the id_rsa.pub file cannot be copied in vim, otherwise an error will be reported:
Key is invalid. You must supply a key in OpenSSH public key format.
The following command can be used to verify the success of the above configuration:
ssh -T [email protected]
If Are you sure you want to continue connecting (yes / no)? Select yes.
You've successfully authenticated, but GitHub does not provide shell access. It means the configuration is successful.
3. Establish a new warehouse locally and associate it with a remote warehouse
(1) Establish a new local warehouse
Create a new folder as a local warehouse.
mkdir repository_name #Create a new local repository
cd repository_name
git init
git add filename # (or git add *. *)
git commit -m "first commit"
Create a new remote repository on Github accordingly.
Click New to enter the create new warehouse interface, fill in the corresponding information in the create warehouse interface.
Associate the local warehouse with the remote warehouse.
git remote add origin https://github.com/username/repository_name.git
git push -u origin master
若出现错误:error: The requested URL returned error: 403 Forbidden while accessing ...
Modify the url in the .git / config file
url = https: // github.com/username/repository_name.git # before modification url = https: // username: [email protected]/username/repository_name.git # after modification
4. Join the team remote warehouse
First of all, the team warehouse exists, and has received an invitation or permission to join the team warehouse.
The team warehouse is generally private, first copy the code of the team warehouse to the local
git clone htttps://username:[email protected]/team_name/team_repository_name
Grab the required branch
git fetch origin remote_branch_name:local_branch_name
Go to desired branch
git checkout local_branch_name
5.git other common operations
(1) Create a new branch
git checkout -b new_branch
(2) Add files and remark information
git commit -a -m "commit information"
(3) Add branch to remote
git push origin local_branch_name:remote_branch_name