This is my second article on getting started

background

Nowadays, git used in our daily work and study is very frequent, especially when they are in the collaborative development with your colleagues in your company, if you are not familiar with the basic operation of git, so your daily job will be difficult (and, of course, not absolute, some companies use the SVN), below summarize the development project in the company when I used the basic operations of a git

Cloning project

git clone http://***********. Git //clone with your project address
Copy the code

Create a new branch

git branch *** // Create a new branch
git checkout -b *** // Create and switch to the branch
git remote update origin --prune // This code is used to update the remote branch when the branch is not displayed
git push origin *** // Push the branch
Copy the code

Deleting an existing branch

git push origin :*** // Delete the existing branch
Copy the code

Switch branches and commit pull code

git checekout *** // Switch to ***
git pull // Pull the code
git push // Submit the code
Copy the code

A series of operations that are merged into the Master branch when branch development is complete

git checkout dev
git pull
git checkout master
git merge dev
git push origin master // Push the merged code to the remote master branch
Copy the code

The operation of updating something from the master branch to another branch is similar to the operation of merging something from the master branch

git checkout master
git pull
git checkout dev
git merge master
git push origin dev
Copy the code

When development on the branch is complete, commit the branch details (most commonly used in the work)

git add . // Add the code to the staging area
git commit -m '* * *' // Submit the code locally
git pull // Pull the code once before committing to the remote (because there may be code conflicts, to resolve conflicts)
git push // Push the code to the remote library
Copy the code

What to do when your code needs to roll back to a certain version

git reset --mixed 5b7f5a67 //5b7f5a67 represents the COMMIT ID (SHA) that you generate for each commit
git push origin **** --force // Force the rollback code to a branch, with *** representing the branch name

// Git reset can be followed by three parameters: soft, hard, mixed.
// I will not explain the reason here, because the principle is complicated, the first two are prone to problems.
// Use mixed to address most of your fallback needs. If you want to use mixed to address most of your fallback needs, you can leave a message
Copy the code

conclusion

This is the git basic operation that I use in my daily work, welcome friends to point out if there is something wrong, learn from each other and make progress together!!