Git-Easy Guide

Source: Internet
Author: User

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

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

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 yours 工作目录 , it holds the actual file, and the second is 缓存区(Index) that it's like a cache area, temporarily saving your changes, HEAD and finally, pointing to the results of your most recent 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 "代码提交信息"
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

Graphical interface of links and resources

    • 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

Git-Easy Guide

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.