git Concise user Guide [go]

Source: Internet
Author: User

Git-Easy Guide

A handy guide to getting Started with git, with advanced content,;).

Tweets

Roger Doudler

Thanks:@tfnico, @fhd and namics

Other languages中文版, Deutsch, español, français, Italiano, Nederlands , Português, русский, Türkçe,

?????? , Japanese , ???

If you have any flaws, please go to GitHub

Setup

Installation

Download git OSX version

Download git Windows edition

Download the git Linux version

Create a new warehouse

Create a new folder, open it, and then execute

Git init

To create a new git repository.

Check out the Warehouse

Execute the following command to create a cloned version of the local repository:

git clone/path/to/repository

If this is the repository on the remote server, your command will look like this:

git clone [email protected]:/path/to/repository

Work flow

Your local repository consists of three "trees" maintained by git. The first one is your working directory , it holds the actual file, the second is the buffer (Index),It's like a cache area, temporarily saves your changes, and finally the HEAD, which points to the result of your last commit.

Add and submit

You can schedule changes (add them to the cache) and use the following command:

git add <filename>

git add *

This is the first step in the Git basic workflow, using the following command to actually commit the changes:

Git commit-m "code submission Information"

Now, your changes have been submitted to HEAD, but not to your remote repository.

Push changes

Your changes are now in the HEAD of the local repository. Execute the following command to commit the changes to the remote repository:

Git push Origin Master

You can replace master with any branch you want to push.

If you have not cloned an existing repository and want to connect your warehouse to a remote server, you can add it using the following command:

Git remote add Origin <server>

So you can push your changes to the server you added.

Branch

Branches are used to insulate the development of features. When you create a warehouse,master is "default." Develop on other branches, and then merge them onto the main branch when you are finished.

Create a branch called "feature_x" and Switch to the past:

Git checkout-b feature_x

Switch back to the main branch:

git checkout Master

Then delete the new branch:

Git branch-d feature_x

Unless you push the branch to the remote repository, the branch is not visible to others :

Git push Origin <branch>

Update and merge

To update your local repository to the latest changes, do the following:

Git pull

To get (fetch) in your working directory and Merge (merge) remote changes.

To merge other branches into your current branch (for example, Master), execute:

git merge <branch>

In both cases, Git will try to automatically merge the changes. Unfortunately, automatic merging is not always successful, and can lead to conflicts (conflicts). This time you need to modify these files to human flesh merge these conflicts (conflicts) . After you've changed, you'll need to execute the following commands to mark them as merged successfully:

git add <filename>

Before merging the changes, you can also use the following commands to view:

git diff <source_branch> <target_branch>

Label

It is recommended to create a label when the software is published. This is an old concept, also in SVN. You can execute the following command to create a label called 1.0.0 :

git tag 1.0.0 1b2e1d63ff

1b2e1d63ff is the first 10 characters of the commit ID you want to tag. Use the following command to get the commit ID:

git log

You can also use the submission ID for fewer of the first few, as long as it is unique.

Replace local changes

If you do something wrong (naturally, this is not possible), you can replace the local change with the following command:

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, as well as new files, are unaffected.

If you want to discard all of your local changes and commits, you can get the latest version on the server and point your landlord branch 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

When the history is displayed, only one line of comment information is displayed:

git config format.pretty oneline

To add files interactively to the buffer:

Git add-i

Links and Resources

Graphical interface

    • GITX (L) (OSX, open source)
    • Tower (OSX)
    • Source Tree (OSX, free)
    • GitHub for Mac (OS X, free)
    • Gitbox (OSX)

Guides and Manuals

    • Git Community Reference Book
    • Professional Git
    • Like git thinking
    • GitHub Help
    • A graphical Git guide

from:http://www.bootcss.com/p/git-guide/

git Concise user Guide [go]

Related Article

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.