How to Use git to create a project and a branch

Source: Internet
Author: User
Tags how to use git

Git config-global user. Name "your name"

Git config-global user. Email "you@example.com"

Create a folder for Storing Projects

The GIT init command is used to initialize the project in the current directory.


Creates a hidden file. Git.

Create the main. c file

Create a. gitignore file and ignore the project files in the file.

Git Status view project status

Git add ..

Create a snapshot for my current project (the snapshot is only registered with the name, the snapshot is not equal to the record, the snapshot is called the Index)

Git commit is used to permanently write the content registered in the snapshot to the GIT repository, that is, the developer has prepared to submit his own development results.

Note: When writing development logs, the first line must be a general development information of less than 50 characters, and the second line must be empty lines, the third line starts to describe the development information in detail. This is because the email mechanism in many version service systems selects the first behavior email question in log.

The GIT commit-a command can directly submit all the modifications, eliminating the need for git add, git diff, and git commit operations.

Note: you cannot add new files or folders. Therefore, if you add new files or folders, you must honestly Add. Git first, and then git commit.

Git log-P

If you think that the information provided by git log is too thin, you can use git log-P. In this way, git not only provides the development log, but also shows the code differences for each development version.

Conclusion: First add the file you modified by git, then git diff and git status to check and confirm, then commit by git commit, then enter your development log, and finally confirm the GIT log again.

Create Branch

Git branch experiment create a branch

Enter git branch directly. If no subsequent parameter is added, it indicates that git is allowed to list all existing branches.

The branch with an asterisk (*) indicates the current branch.

Switch branch to experiment

Git checkout Experiment

Branch program OK

Git commit-

Submit work on the branch


Switch trunk

Git checkout master

Git commit-

Git merge Experiment

Merge branches to main roads

Merging failed

View source files

Git is confused because it does not know whether to put the Hello world line in front or the reporting function in front.

Modification conflict

Resubmit

Git commit-

Gitk graphical git Management Interface

After merging the branches, delete them.

Git branch-d experiment

-D, indicating "deleting a branch after the Branch has been merged into the trunk ". If-D is used in upper case, the Branch is deleted in any case ",

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.