Create, switch, merge, and delete operations for GIT branch-related tips

Source: Internet
Author: User

First, view existing branches

View existing branches: git branch commands;

 
 

As can be seen from the result, there is now only one branch master;

Second, create a branch

Create a branch: A per- git branch name, you can create a branch, you can view the branch after the branch is created, the currently used branch will be displayed as green, preceded with "*", if not currently used, the display is white, and there is no "*" prefix;

 
 

Third, switch branches

Toggle Branch: git checkout Branch name, after switching branches, the operation in the branch, file changes will not be reflected in the Master Branch, the main branch change, will be reflected in other branches;

 
 

About the main branch and other branches:

--Branch Editor: Existing two branch master branches, and the Branch1 branch just created, switch to Branch1 branch, create a file description_branch1.txt in Branch1;

--Other branch files do not affect the main branch: then switch back to master branch and find no Description_branch1.txt file, create a file description_master.txt;

--The main branch affects other branches: In the switch back to the Branch1 branch, a description_master.txt file is found;

Contrast process:

View the Project branch:

 
 

– Branch Results:

Branch1 

Switch to BRANCH1 branch:

 
 

– Switch results:

 
 

To view the files under the Branch1 branch:

 
 

– View file results:

Androidmanifest.xml ic_launcher-web.png Res 
assets    Libs     src 
bin     proguard-project.txt 
Gen     

To create a file:

 
 

Add this file to the local cache:

 
 

Submit Local Cache: Note that this must be submitted, and if no cache is submitted, this file will appear in the main branch as well;

 
 

– Submit Results:

[Branch1 7f5785e] Add a description of Branch1 
 1 file changed, 0 insertions (+), 0 deletions (-) 
 

To view the files under this branch:

 
 

– View file results:

Androidmanifest.xml  Libs 
assets     proguard-project.txt 
bin      project.properties 
<strong >description_branch1.txt</strong> Res 
Gen      src 

Switch back to Main branch:

 
 

– Toggle Branch Results:

Switched to branch ' master ' 

To view the primary branch file:

 
 

– View file results: No files added in Branch1;

Androidmanifest.xml ic_launcher-web.png Res 
assets    Libs     src 
bin     proguard-project.txt 
Gen     

Iv. Submission of Branches

Commit the Branch command: Submit the local branch to the GitHub;

 
 

V. Branch merging

Merge Branch command: After merging the branches, some of the files in the branch are also displayed in the main branch, equivalent to copying the files from the Branch1 branch into the master branch;

 
 

Merge results:

Updating f1bb97a. 7f5785e 
Fast-forward 
 description_branch1.txt | 0 
 1 file changed, 0 insertions (+), 0 deletions (-) 
 

Vi. Deleting branches

To delete a branch command:

 
 

Force Delete Branch Command: If the BRANCH1 branch has not been merged, Git is not allowed to delete the branch, and if you want to delete the branch, you can only use the following command to force the branch to be deleted:

 
 

Summarize

The above is the entire content of this article, I hope the content of this article for everyone's study or work can help, if there is doubt you can message exchange.

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.