Git branch usage Summary
12724 people read comments (1) collect reports
Branchgit
Git Branch
Git branch without parameters: list existing local branches and add the "*" sign before the current branch. For example:
# Git Branch
* Master
Newbranch
Git branch-r lists remote branches, for example:
# Git branch-R
M/master-> origin_apps/m1_2.3.4
Origin_apps/hardware/test
Origin_apps/M1
Origin_apps/m1_2.3.4
Origin_apps/Master
Git branch- List local branches and remote branches, for example:
# Git branch-
* Master
Newbranch
Remotes/M/master-> origin_apps/m1_2.3.4
Remotes/origin_apps/hardware/test
Remotes/origin_apps/M1
Remotes/origin_apps/m1_2.3.4
Remotes/origin_apps/Master
Git branch creates a new local branch. Note that only the branch is created here, and no branch switch is performed. For example:
# Git branch newbranch2
# Git Branch
* Master
Newbranch
Newbranch2
The current branch is still the master, and no switchover is performed.
Git branch-M |-M oldbranch newbranch rename the branch. If a newbranch name already exists, use-m to rename the branch. Otherwise, use-m to rename the branch.
Git branch-d |-D branchname Delete branchname Branch
Git branch-d-r branchname Delete remote branchname Branch
Example:
An example in git help Branch:
$ Git clone git: // git.kernel.org/pub/scm/.../linux-2.6 my2.6
$ CD my2.6
$ Git branch my2.6.14 v2.6.14
$ Git checkout my2.6.14
The third line conforms to the format of git branch <branchname> [<start-point>], that is, v2.6.14 is the start-point, and a new local branch branchname is created.
Get git Repository
Initialize a version Repository
Git init
Clone remote version Library
Git clone [email protected]: WordPress. Git
Add the remote repository origin. The syntax is GIT remote add [shortname] [url].
Git remote add origin [email protected]: WordPress. Git
View remote Repository
Git remote-V
Submit your modifications
Add the modified file to the temporary storage area
Git add.
If you automatically track files, including those that have been manually deleted and are in the deleted status
Git add-u
Submit your modifications
Git commit-M & quot; Your Comment & quot;
Push your updates to the remote server. Syntax: git push [remote name] [local branch]: [remote branch]
Git push origin master
View File status
Git status
Tracking new files
Git add readme.txt
Remove files from the current trail list and delete all files
Git RM readme.txt
Only deleted in the temporary storage area. The files are retained in the current directory and will not be tracked.
Git Rm-cached readme.txt
Rename a file
Git MV reademe.txt readme
View submitted history
Git log
Modify the comments submitted last time using the-amend Parameter
Git commit -- Amend
If you forget to submit some modifications, only one of the following three commands will be submitted.
Git commit-M "addreadme.txt & quot;
Git add readme_forgotten
Git commit-amend
Suppose you have used git Add. To add the modified files A and B to the temporary storage Zone
Now you only want to submit file a and file B.
Git reset head B
Cancel File Modification
Git checkout -- readme.txt
Basic branch management
Create a branch
Git branch iss53
Switch the working directory to iss53
Git chekcout iss53
Combine the preceding commands to create the iss53 branch and switch to iss53.
Git chekcout-B iss53
Merge iss53 branches. The current working directory is master.
Git merge iss53
After merging, no conflict occurs. Delete the iss53 branch.
Git branch-D iss53
Pull the data from a remote repository. The syntax is GIT fetch [Remote-name].
Git fetch
Fetch pulls the latest remote warehouse data but does not automatically go to the current directory.
Git pull
View remote Repository Information
Git remote show origin
Create a local Dev branch to track the develop branch of the remote Repository
Git checkout-B Dev origin/develop
- The version pointed to by head is the current version. Therefore, git allows us to move between version history and use commandsGit reset -- hardcommit_id.
- Before shuttle, useGit logYou can view the submission history to determine which version to roll back.
- To return to the future, useGit reflogView the command history to determine which version to return.
Git ResetThe command can be used to roll back the version or to the workspace. When we use head, it indicates the latest version.
Rollback:
git reset --hard HEAD^
git reset --hard 3628164
Procedure
git reflog
git push origin :branch-name
There must be no less space before the colon. The principle is to separate an empty space.PushToServer.
Common git commands (Lite version)
List local branches
Git Branch
Git branch-a local and remote
Git branch-r remote Branch
Create Branch:
Git branch <newbranch>
Git checkout <newbranch>
Equivalent:
Git checkout-B <newbranch>
Rename Branch
Git branch-M |-M oldbranch newbranch rename the branch. If the newbranch name Branch already exists, use-m to rename it forcibly. Otherwise, use-m to rename the branch.
Delete Branch:
Git branch-d |-D branchname Delete branchname Branch
Git branch-d-r branchname Delete remote branchname Branch
Add the remote repository origin. The syntax is GIT remote add [shortname] [url].
Git remote add origin [email protected]: WordPress. Git
View remote Repository
Git remote-V
Push local files to remote Libraries
$ Git push origin test: Master // submit the local test branch as the remote master Branch
$ Git push origintest: Test // submit the local test branch as the remote test Branch
Common git commands