Git branch Branch usage guide

Introduction: Git is widely adopted due to its good distributed characteristics. This article will review the key instructions at its core.

Create Branch

git checkout -b ‘branch name’

View remote branches

git branch -a

Options:

-a View all branches 
-r View remote branches 
-l View local brnach

View local branch branch

git branch

switch branch

git checkout ‘branch_name’

delete local branch

git branch -D br_name

delete remote branch

git push origin :br (with a space after origin)

Submit an instruction

Add files to Git management

git add xxx.java

Submit to the local Repository

git commit -m ‘comment here’ xxx.java ….

-m : Here are mainly comments for submitting code changes 
-a: Refers to submitting a list of all changed files at one time

push instruction

Push to master on remote host

git push origin master

Push the current branch to the remote Repository

git push origin

Push all local branches to the server

git push –all origin

fetch instruction

Meaning: Download the remote code to the local, do not merge

git fetch origin master

View the difference between the local master and the remote master 
git log -p master..origin/master

Merge code 
git merge origin/master

Another more explicit approach is when the remote code is downloaded to the local as a branch, and then merged

git fetch origin master:t-branch 
git diff t-branch 
git merge t-branch

Pull command

Download remote code to local and merge it automatically

git pull origin master

In general, it is recommended to use fetch, and decide whether to merge with the remote master code according to the actual situation.

Tag instruction

Create Tag

git tag -a ‘tag_name_v0.1.2’ -m ‘comment message’

Query all current tags

git day

Query Tags by pattern matching

git tag -l ‘v0.1.*’

Push the current specific tag to the remote

git push origin tag_name

Push all current tags to remote

git push origin –all tags

Merge command

switch to master branch

git checkout master 
will merge xxx_branch to master 
git merge xxx_branch

View git master information

git remote show origin

* remote origin
  Fetch URL: http://source.xx.com/app/xx-ImageService.git
  Push  URL: http://source.xx.com/app/xx-ImageService.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (fast-forwardable)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

Summarize

The summary here cannot cover all usages one by one. For more detailed usages, you can check git help for more information.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325164157&siteId=291194637