Git version control and GitHub use

Source: Internet
Author: User
Tags commit svn version control system git clone git commands
Git is an open source distributed version control system for managing projects in an agile and efficient manner. The biggest feature of Svn,git is distributed, where everyone has a cloned repository, so committing code, viewing logs, creating branches, merging branches, fallback, and so on, is done directly locally without the need for a network. Of course, the local repository needs to be synchronized with the remote shared repository, which requires a network.
GitHub, as a git service provider, can host your git repository and can be hosted free of charge for open source projects, which is good for open source projects. GitHub uses sign up for a GitHub accountFirst you need to have a GitHub account, register the address Https://github.com/join, remember your username and mailbox, here such as Mycwq and mycwq@example.com (the mailbox must be valid and need to be verified)
Create a git repositoryLog in to your GitHub account and click on the + sign in the top right corner to create a repository (creating a new repository). The repository is also called the Data Warehouse
You can keep the above options unchanged and click the Green button to complete the creation. After successful fetch to GIT library address https://github.com/mycwq/test.git
clone repository to localis to get all the contents of a Git shared library, make sure the system has the GIT command tool installed, and no reference to this article. $ git clone https://github.com/mycwq/test.git
Commit to shared repository git this operation has 2 steps, the first step is to submit the code to the local repository, the second step is to synchronize the local repository to the remote shared repository
If it is used for the first time, you need to set the account and mailbox $ git config--global user.name "Mycwq"
$ git config--global user.email "mycwq@example.com"
The following example shows how to submit content to the repository: $ echo "# test" > readme.md $ git add readme.md $ git commit-m "first commit" $ GIT push origin Master
Then, follow the prompts to enter your account and password. Once successful, you can see what you just submitted on GitHub.


git repository vs. command diagramIn Ruan Yi Feng Blog to find this picture, very valuable reference. Article here, may wish to see it
Above, fetch, clone, push, pull are all remote operations, the others are done locally.

Common git commands
Command Description
Git diff
Displays changes to all files in the repository, but does not include files outside the version
git status
Tree displays the general situation of the repository, such as which files have been changed and which have not been added to the repository
git log
View Submission Log
git clone < library address > Cloning a remote repository to a local
git fetch
Synchronizing updated content of the repository to the local repository
git add The index records the file to be submitted and commits at Git commit
Git commit Commit changes to the local repository
git push Synchronizing the local repository to the shared repository
Git remote List all remote hosts
GIT branch < branch name > New Branch
git checkout < branch name > Switch to branch (set a branch to working directory)
git checkout-b < branch name >
Checkout branch, equivalent to git branch < branch name > && git Checkout < branch name >
Git merge < branch name > Merge a branch into the working directory
Git pull
The shared repository is synchronized to the local repository and merged into the current working directory. Equivalent to git fetch plus git merge < branch name >
Git blame <filename>
Get detailed modification information for each line of the file, including author, date, and journal number

git branch Management common commands for branching
Establish a branch $ git Branch branch1
List all Branches $ git Branch branch1 * above, * indicates the branch currently in use, that is, the branch where the working directory resides. If it is a remote warehouse GitHub branch case: $ git branch-r origin/branch1 origin/master
Switch branches $ git checkout branch1 switched to branch ' BRANCH1 ' is equivalent to BRANCH1 as the current branch, can git branch see the changes
Delete Branch $ git branch-d branch1 the above command, GIT checks whether the branch has been merged into the upstream branch, and if not, it cannot delete the branch. But if you really want to delete the branch, use the-D parameter to forcibly delete: $ git branch-d branch1 if you want to delete the branch Branch1 on GitHub, $ Git push origin--delete branch1 or the git pu SH origin:branch1
Rename Branch $ git branch-m branch1 branch2
Merging branches Git has three merge branches, straight merge, squashed commits and cherry-picking differ as follows: 1, direct merge (straight merge) merges all the history of a branch into the current branch, the original branch has many With fewer commits, the current branch increases the number of log commands as follows: $ git merge branch1 2, patchwork merge (squashed commits) to compose a log submission for all history on a branch, so that the current branch cannot see each commit of that branch  Recording.   The command is as follows: $ git merge--squash branch1 $ git commit-m ' branch1 merge ' 3, pick merge (cherry-picking) merge some of the commit logs of the branch into the current branch    The command is as follows: $ git cherry-pick 7654321 or more, 7654321 is the hash value of the commit log, which can be found from git log, which is 40 bits, but git usually needs to be identified by the previous 7 bits. If you need to merge multiple logs, but don't want git to merge at once every time, you can change this command: $ git cherry-pick-n 7654321
Submit to Remote Branch Commit to remote repository GitHub branch branch1, branch does not exist will automatically create GIT push Origin branch1
Export Branch Similar to SVN export, such as exporting the Master branch: $ git archive master-o. /master.zip
use of BranchesHere with the simplest and most practical sub-branch model, that is, two branches, a record master, another note develop, the project under the develop development, not regularly merged into the master branch.
First, we need to locate the relationship between Master and develop: master: The main branch, the version of the production environment develop: sub-branch, is the version of the development environment
Git has a master branch when it is created, and we need to create another branch. Use the following command to create a develop branch from the master branch location and switch the current branch to the develop branch

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.