Git initialization steps
Download Git and select the version corresponding to your system to download it.
Generate the ssh key on your computer, open the terminal, execute
if the execution is successful, switch to the ~/.ssh directory, the directory should be as follows shown. Copy the contents of id_rsa.pub.ssh-keygen -t rsa -C "UVS or your own email address"
Take Github as an example, go to settings -> SSH and GPG keysand use the cat command to view the content of the file id_rsa.pub, then copy it over, click add ssh key, this step is equivalent to putting your public key on Github for hosting .
Configure Git username and email globally
git config --global user.name "username"
git config --global user.email "username@uvsociety.org"
After completing the above four steps, you can happily pull code development. Different from the https pull method, the https method needs to manually enter the username and password before each submission. After the ssh method is configured, Git will use your local private key and the public key of the remote warehouse to verify whether it is a pair of secrets. key, which simplifies the operation process.
Git basic operations
Add file to staging area
git add
Add a file to the temporary storage area, followed by multiple files, separated by spaces
git add xxx
Add all currently changed files to the staging area.
git add .
Commit the temporary changes, and a new editor will be opened for editing
git commit
Commit the staged changes and make a note
git commit -m "you message"
same as git add . && git commit -m
git commit -am
Modify the latest submitted information, this operation will modify the hash value of the commit
git commit --amend
Pull the code from the remote repository and merge it to the local, which can be abbreviated as git pull is equivalent to git fetch && git merge
git pull <remote hostname> <remote branch name>:<local branch name>
Merge using rebase mode
git pull --rebase <remote hostname> <remote branch name>:<local branch name>
git fetch
Unlike git pull, the git fetch operation only pulls remote changes, and does not automatically perform a merge operation. No effect on your current code
Get updates for a specific branch of the remote repository
git fetch <remote hostname> <branch name>
Get updates on all branches of the remote repository
git fetch --all
git branch
Create a new local branch, but don't switch
git branch <branch-name>
View local branch
git branch
View remote branch
git branch -r
View local and remote branches
git branch -a
delete local branch
git branch -D <branch-nane>
rename branch
git branch -m <old-branch-name> <new-branch-name>