git Concise tutorial

Source: Internet
Author: User
Tags tagname

"Git tutorial"

http://www.liaoxuefeng.com/(Liu Xuefeng blog)

http://rogerdudler.github.io/git-guide/index.zh.html (git Concise tutorial)



"Common Commands"

PS: Git command in MacOS system environment.


Work flow

Your local repository consists of three "trees" maintained by git.

> workspace , which holds the actual folder.

> Staging Area (Stage), it is like a cache area, temporarily save your changes.

> HEAD, which points to the result of your last commit.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5A/01/wKiom1TyrgaCJVD2AAC5zyGygMg610.jpg "title=" 1.png " alt= "Wkiom1tyrgacjvd2aac5zygygmg610.jpg"/>


Configure a native git username and mailbox | Config

After you've just installed Git on this machine, you need to configure the information.

git config--global user.name "Shahdza"

git config--global user.email [Email protected]


Initialize git repository | Init

# Create a folder and go to the Demo directory

mkdir Demo

CD Demo


# Initialize the Git repository (turn the Demo folder into a git repository)

Git init


Add and Submit | Add, Commit

is done in a local git repository and does not alter the remote repository version.

# Add files to the warehouse (put in staging area)

git add readme.txt

git add *


# submit files added to staging area to the warehouse

git commit-m "Submit message"


Clone Warehouse | Clone

# Clone a remote repository to a local warehouse

git clone https://github.com/shahdza/Demo.git


# clone local repository to another local path

git clone /localpath


Remote Push | Remote, push

# Associate a local warehouse with a remote library

git remote add Origin Https://github.com/shahdza/Demo.git


# Push all content of Master branch for the first time

Git push-u Origin Master

# Push the latest changes to the Master branch (you can also push other branches)

Git push Origin Master


View Submission Information | Status, diff, log, reflog

# View the current status of the warehouse

git status


# View the contents of a file that has been modified (the difference between the workspace and the local Git repository when not yet commit)

git diff Readme.txt


# View commit history from the nearest to the farthest

Note: For example, there are 100 versions, with reset back to the 50th version, then log will only show the 1~50 's commit log

# # will show the version number, submission date, submission information

git log

git log--pretty=oneline


# View the history of the Operation commands (each action command is logged)

Git reflog


Version Fallback | Reset--hard

# Previous version, last version, 100 + versions

git reset--hard head^

git reset--hard head^^

git reset--hard head~100


# fallback to the specified version (via version number)

git reset--hard 3628164


Discard Changes to Workspace | Checkout--

# One is Readme.txt since the modification has not been put into the staging area, now, undo changes back to the same state as the repository;

# One is that Readme.txt has been added to the staging area and has been modified, and now the undo changes go back to the state that was added to the staging area.

In short, it is the state of getting this file back to the last time [git commit] or [git add].

git checkout-- readme.txt


Undo Staging Area modification (unstage) and re-put it back in the workspace | Reset HEAD

# after execution, the staging area is clean and the workspace has been modified

git reset HEAD readme.txt


Delete a file in the warehouse (the workspace file is also deleted) | RM

# Delete file will be put into staging area, can use [git reset HEAD file] and [git checkout-file] Undelete

git rm readme.txt


Branch Management | Branch

# Create a branch

Git branch <name>

# Toggle Branch

git checkout <name>

# Create + Toggle Branch

Git checkout-b <name>


# Merge a branch into the current branch

git merge <name>


# Delete Branch

Git branch-d <name>

# forcibly deleted

Git branch-d <name>


# View Branches

Git branch

# View Branch Merge Chart

git log--graph--pretty=oneline


Tag Management | Tag

# Label The branches

# # The current version labeled

git tag v1.0

# # A version labeled

git tag v0.9 6224937


# push tag to remote repository

# # Push a tag

git push Origin <tagname>

# # Push All tags

Git push Origin--tag


# Delete Tags

git tag-d v0.1


# Remove Remote Tags

# # needs to be deleted locally before being remotely deleted

git tag-d v0.9

git push origin:refs/tags/v0.9


# View All Tags

git tag


# View a tag information

Git show <tagname>


Ignoring special files |. gitignore

1. Create a special . Gitignore file in the root directory of your Git workspace.

2. In the . Gitignore file, add the files that you want to ignore.

3. Special documents Daquan:Https://github.com/github/gitignore


Multi-person collaboration

Master Branch: used to manage the official version.

Dev Branch: used to manage a developing version.

Bob Branch:Bob creates the branch himself, Bob Works under this branch, and then merges to the Dev branch.

Michael Branch:A branch that Michael creates himself, works under this branch, and then merges into the Dev branch.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/FF/wKioL1TzJkXAJExvAACWU4ShLWA947.jpg "title=" 2.png " alt= "Wkiol1tzjkxajexvaacwu4shlwa947.jpg"/>


# Crawl Branches

# # from remote library clone, by default, you can only see the local master branch.

git clone https://github.com/shahdza/Demo.git


# locally created and remote branches corresponding to the dev branch

git checkout-b Dev Origin/dev


# Establish Association of local Dev Branch and remote Dev branch

Git branch--set-upstream Dev origin/dev


# Update Branch

# # When a small partner has pushed his submission to the Origin/dev branch.

# # and you happen to have made changes to the same file and tried to push it.

# # Push failed because the latest submission from the small partner conflicts with the commit you are trying to push

# # need to catch the latest submissions from Origin/dev

# # Then, merge locally, resolve conflicts, and then push

Git pull



This article is from the "Summer Wind" blog, please be sure to keep this source http://shahdza.blog.51cto.com/2410787/1616345

git Concise tutorial

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.