git use and common commands _linux shell

Source: Internet
Author: User
Tags commit diff git clone git commands

The process used by git in a team project

1. First from a git remote repository to the clone project to the local

git clone warehouse Address

2. Create a development Branch

Normally we write code that does not write on the master branch, but creates a new branch

Git checkout-b test

3. Code modification on the test branch, such as completion of a function development

4. Submit code to test branch after modification

git Add.
Git commit-m "Your comment"

5.review code (not required)

After you have developed a feature on the test branch, it is recommended that you review the modified code by comparing it with the master branch

6. Switch to Master Branch

git checkout Master

7. Update Master Branch

Git pull (keep the local master consistent with the latest server code)

8. Switch to test branch again

git checkout Test

9. Update Master code to test branch

Git merge master (merges the master branch into the current branch)

10. Commit the test branch to the server after the conflict has been processed

Git push Origin branch name

11. Submit the Merge Request

After submitting the merge request, the code approval team colleagues will review the submitted code, and no problem will agree to merge requests and merge the code from the test branch into the master branch

Git using tips

The use of Stash

Sometimes there is a scenario where you develop a feature on a local branch and there is an urgent bug that needs to be handled, and the current feature is not developed and you do not want to commit, commit, or switch branches. At this point, you can use the Stash command to temporarily save the current code.

git Add.
Git stash

At this point, the code you modify will be staged to a stack-like container, where the code reverts to the last commit.
You can perform Git stash list to see if a listing of the staging stack is available.

After the staging code can switch branches, you can switch to other branches to fix the bug, and then switch to the branch, perform the following command to restore

Git stash pop

The use of blame

Sometimes when we modify someone else's code, we want to see who wrote the particular line of the file, and we can use blame (blame, to hold it accountable).

git blame file

After you execute the above command, each row will show who submitted the specific, and you can flip the page with the paging key.

git command alias settings

Do you think it's a bit troublesome to knock on git command? Yes, I feel the same way.
We can set the alias in the ~/.gitconfig file, plus the following lines

[Alias]
 St = Status
 CI = commit
 br = Branch
 CO = checkout
 df = diff

Aliases can be set according to their own habits.

Common git commands

git branch-r/-a  View Remote branch/local and remote branch
git checkout branch name  Switch branch
git checkout-b branch name  New and switch to new branch
git BRANCH-D Branch name  Delete local branch
git pull   update local branch to latest
git merge branch name  Merge a branch to the current branch
git diff   View content that is not currently add modify
git diff--cached  View already add, no commit changes
git diff head   is the merge git log of the above two commands
-- Oneline--number display log, each log shows a row, display number of
git Add.   Add modified code to registers
Git push Origin branch name  pushes the specified branch to the server
git status to   see which modifications have been added to the staging area pending submission and which are not included in the registers
git Reset head filename  cancels temporary storage of a file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.