Create a branch
Git branch
There are no parameters to display all local branch names in the local repository.
The current checkout branch is preceded by an asterisk.
Git branch newname
Creates a new branch on the currently checked out branch, named NewName.
git checkout newname
Check out the branch, that is, switch to the branch called NewName.
git checkout–b newname Master
This command merges the above two commands: Creates a branch NewName branch on the master branch and checks out to that branch.
merging changes between branches merge
The merge operation merges two or more branches together, and there are actually several branch merge methods, the main three of which are described below:
1. Direct merge (straight merge):
Merge the historical tracks of the two branches and converge them together.
For example, to merge all the things on the dev branch into the master branch:
First to Master branch:git checkout master
Then merge the dev:git merge dev
Note that the merge is fast-forward without parameters , that is, Git moves the pointer of the master branch directly to the front of Dev.
In other words, if you go down one branch and you reach another, git will simply move the pointer as it merges the two, so this merge becomes fast-forward (fast-forward).
2. Press-Fit Merge (squashed commits):
Press a commit entry on a branch to submit to the tip of another branch.
Press all commits on the dev branch to synthesize a commit on the main branch, i.e. press-fit commit:
3. Picking merge (cherry-picking):
Picking changes to a commit entry on another branch to the current branch.
Each commit produces a globally unique commit name that can be used for picking submissions.
For example, a commit on Dev is called: 321d76f
Merge it into master:
git checkout Master
Git Cherry-pick 321d76f
To pick multiple commits, you can pass the-n option to the git cherry-pick command, such as:
Git cherry-pick–n 321d76f
This allows for staging without immediate submission after selecting this change, and then the next pick operation, which can be submitted once the required submissions have been selected.
Conflict Handling
When two branches make different changes to the same text block of the same file and try to merge, Git cannot merge automatically, called Conflict (conflict). Resolving conflicts requires manual processing.
For example, in the master branch, want to merge the dev branch, resulting in a conflict, open the file content can see a conflict:
<<<<<<< headtest in master=======test in dev>>>>>>> Dev
The <<<<<<< tag conflict begins with the contents of the current branch.
The HEAD points to the commit of the current branch's distal.
After the ======= ,>>>>>>> was the code on the other branch to merge over.
Dev after >>>>>>> is the name of the branch.
For a simple merge, edit it manually, then remove the tags, and finally add the commit as usual.
Delete Branch
Some branches have no need for long-term preservation, such as the code in the branch has been tagged and published, or the experimental branch has successfully completed the work or abandoned, and so on.
Note : A labeled Branch, when git deletes the branch, all the historical traces from the beginning of the version tree to the tag are preserved, and the delete branch operation simply removes the name of the branch itself, so it is not necessary to save the branch for a long period of time.
In other versions of the control tool, deleting a branch usually means deleting all the historical traces on the branch, so it is not considered necessary to save it because it is labeled.
Delete a branch Dev2:
be strongly deleted.
Branch Rename
To rename a branch:
git branch–m oldname newname
- m does not overwrite the existing branch name, meaning that if a branch named NewName already exists, the hint already exists.
If you change to- m to overwrite an existing branch name, you will be forced to overwrite the branch named NewName, which is prudent.
-----------------------------------------------------------
From: http://www.cnblogs.com/mengdd/p/3585038.html
Git Branch management and conflict resolution