Git-Simple Guide

Source: Internet
Author: User
Help you get started with git's Easy Guide, with deep content in the wood ,;).

Tweet

By Roger duler
Thanks: @ tfnico, @ fhd and namics
Other languages: English, Deutsch, epañol, français, Italiano, Nederlands, Portugu ê S, ~~~~~~~, Türk çe,
Zookeeper, Japan, Japan
If any information is missing, go to GitHub to fill it out.

Install

Download
Git OSX

Download
Git for Windows

Download git
Linux

Create a new warehouse

Create a new folder, open it, and then execute
git init
Create a git repository.

Check warehouse

Run the following command to create a clone version of a local repository:
git clone /path/to/repository 
If it is a repository on a remote server, your command will look like this:
git clone username@host:/path/to/repository

Workflow

Your local repository is composed of three "Trees" maintained by git. The first one is yours.Working directory, It holds the actual file; the second isCache area (INDEX)It is like a cache region, saving your changes temporarily; finallyHEAD, Pointing to the result after your last submission.

Add and submit

You can plan changes (add them to the cache) by using the following command:
git add <filename>
git add *
This is the first step in git's basic workflow. Use the following command to submit the changes:
Git commit-M "code submission information"
Now, your changes have been submittedHeadBut it hasn't arrived at your remote repository yet.

Push changes

Your changes are now in the local repositoryHead. Run the following command to submit the changes to the remote Repository:
git push origin master
You can setMasterSwitch to any branch you want to push.

If you have not cloned an existing repository and want to connect your repository to a remote server, run the following command to add the Repository:
git remote add origin <server>
In this way, you can push your changes to the added server.

Branch

Branches are used to isolate feature development. When you create a repository,MasterIs "default ". Develop on other branches, and then merge them into the main branch.

Create a branch named "feature_x" and switch it over:
git checkout -b feature_x
Switch back to main branch:
git checkout master
Delete the new branch:
git branch -d feature_x
Unless you push the branch to the remote warehouse, the Branch isNot what others see:
git push origin <branch>

Update and merge

To update your local repository to the latest changes, execute:
git pull
In your working directoryGet (FETCH)AndMerge (merge)Remote modification.
To merge other branches to your current Branch (for example, Master), execute:
git merge <branch>
In both cases, git tries to automatically merge the changes. Unfortunately, automatic merge is not successful once and may result inConflicts). At this time, you need to modify these files and merge them.Conflicts). After modification, You need to execute the following command to mark them as merged successfully:
git add <filename>
You can also run the following command to view the changes before merging them:
git diff <source_branch> <target_branch>

Tag

It is recommended to create tags when the software is released. This is an old concept, and also exists in SVN. You can run the following command to create1.0.0Tags:
git tag 1.0.0 1b2e1d63ff
1b2e1d63ffIt is the first 10 characters of the submission ID you want to mark. Run the following command to obtain the submission ID:
git log
You can also use the first few digits of the submitted ID, as long as it is unique.

Replace local changes

If you do something wrong (naturally, this is not possible), you can use the following command to replace the local change:
git checkout -- <filename>
This command replaces the files in your working directory with the latest content in the head. Changes that have been added to the cache and new files are not affected.

If you want to discard all your local changes and commits, you can get the latest version on the server and direct your local branches to it:
git fetch origin
git reset --hard origin/master

Useful Tips

Built-in graphical git:
gitk
Color git output:
git config color.ui true
Only one line of comment is displayed:
git config format.pretty oneline
Add files to the cache interactively:
git add -i

Graphical interface for links and resources

  • Gitx (L) (OSX, open source)
  • Tower (OSX)
  • Source tree (OSX, free)
  • GitHub for MAC (OSX, free)

Guide and manual

  • Git community reference books
  • Professional git
  • Think like git
  • GitHub help
  • Graphical git guide 1

Comment

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.