Git Common Commands and tutorials

Source: Internet
Author: User
Tags using git git commands

Common commands: HTTP://HI.BAIDU.COM/SUNBOY_2050/ITEM/FFAB7396672895D11A49DFCC

Streamlined Tutorial: http://lugir.com/git-basic.html

Common Git Commands

Git is a very powerful distributed version control system. It is not only suitable for managing the source code of large open source software, but also has many advantages in managing private documents and source code.

Git Common operation commands:

1) remote Warehouse related commands

Checkout warehouse: $ git clone git://github.com/jquery/jquery.git

View remote repositories: $ git remote-v

Add remote repository: $ git remote add [name] [url]

Delete Remote repository: $ git remote RM [name]

Modify remote repository: $ git remote set-url--push [name] [Newurl]

Pull remote repository: $ git fetch [remotename] [Localbranchname]

Push remote repository: $ git push [remotename] [Localbranchname]

* If you want to submit a local branch test to the remote repository as the master branch of the remote repository, or as another branch called Test, as follows:

$git Push Origin Test:master//submit local Test branch as remote Master Branch

$git Push Origin test:test//submit local test branch as remote Test branch

2 ) Branch (branch) operations related commands

View local branch: $ git Branch

View Remote branch: $ git branch-r

Create local branch: $ git branch [name]----Note that the new branch will not automatically switch to the current branch after it is created

Switch Branch: $ git checkout [name]

Create a new branch and switch immediately to the new branch: $ git checkout-b [name]

Delete Branch: $ git branch-d [name]-----D option can only delete branches that have already joined the merge and cannot be deleted for branches that do not have a merge. If you want to forcibly delete a branch, you can use the-D option

Merge branch: git merge [name]----Merge the branch with the name [name] with the current branch

Create a remote branch (local branch push to remote): $ Git push origin [name]

Delete Remote branch: git push origin:heads/[name] or $ gitpush origin: [Name]

* Create an empty branch: (Before executing the command remember to submit your current branch of the changes, otherwise it will be forced to delete the clean without regret)

$git symbolic-ref HEAD Refs/heads/[name]

$rm. Git/index

$git CLEAN-FDX

3 ) version (tag) operation related commands

View version: $ git tag

Create version: $ git tag [name]

Delete version: $ git tag-d [name]

View remote version: $ git tag-r

Create a remote version (local version push to remote): $ Git push origin [name]

Delete Remote version: $ git push origin:refs/tags/[name]

Merge the remote repository's tag to local: Git pull Origin--tags

Upload local tag to remote repository: $ Git push origin--tags

Create annotated tag:$ git tag-a [name]-M ' YourMessage '

4) sub-module (submodule) Related Operations Command

Add sub-module: $ git submodule add [url] [path]

Example: $git submodule add Git://github.com/soberh/ui-libs.git src/main/webapp/ui-libs

Initialize submodule: $ git submodule init----run only once when the warehouse is first checked out

Update submodule: git submodule update----need to run every time you update or switch branches

To delete a submodule: (4 steps away OH)

1) $ git RM--cached [path]

2) Edit the ". Gitmodules" file to delete the relevant configuration node of the Submodule

3) Edit the ". Git/config" file to delete the relevant configuration node of the Submodule

4) Manually delete the remaining sub-modules directory

5 ignore some files, folders do not commit

Create a file with a name of ". Gitignore" under the repository root and write an unwanted folder name or file with one line per element, such as

Target

Bin

*.db

=====================

Common Git Commands

Git branch view all local branches
Git Status View current status
Git commit Commit
Git branch-a See all the branches
Git branch-r View all local branches
Git commit-am "Init" to submit and annotate
git remote add origin [email protected]:ndshow
Git push origin master pushes files to the server
Git remote show origin shows the resources in origin
Git push Origin Master:develop
Git push Origin Master:hb-dev associate a local library with a library on the server
git checkout--track origin/dev switch to remote Dev branch
git branch-d master Develop delete local library develop
git checkout-b Dev builds a new local branch dev
Git merge origin/dev Merge branch dev with current branch
git checkout dev switch to local dev branch
Git remote show to view the long-range library
git Add.
git RM file name (including path) removes the specified file from git
git clone git://github.com/schacon/grit.git pull the code down from the server
git config--list See all users
Git ls-files look at the already committed
git rm [file name] Delete a file
Git commit-a commits all changes to the current repos
git add [file name] Add a file to git index
Git commit-v you can see the difference in commit when you use the-v argument
Git commit-m "This is the message describing the commit" adds a commit message
Git Commit-a-A represents add, adds all the change to git index and then commits
Git commit-a-V General commit command
git log to see your commit logs
git diff view updates that have not yet been staged
git rm a.a Remove files (removed from staging area and workspaces)
git rm--cached a.a Remove Files (removed from staging area only)
Git commit-m "Remove" Remove files (removed from git)
Git rm-f a.a forcibly remove modified files (removed from staging area and workspaces)
git diff--cached or git diff--staged view the updates that have not yet been submitted
Git stash push to push files to a temporary space
Git stash pop to pop files from scratch space
---------------------------------------------------------
git remote add origin [email protected]:username/hello-world.git
Git push Origin master submits a local project to the server
-----------------------------------------------------------
Git pull local and server-side synchronization
-----------------------------------------------------------------
git push (remote warehouse name) (branch name) pushes the local branch to the server.
Git push Origin Serverfix:awesomebranch
------------------------------------------------------------------
Git fetch is equivalent to getting the latest version from remote to local, not automatically merge
Git commit-a-M "Log_message" (-A is to commit all changes,-M is to add log information) local modifications are synchronized to the server side:
Git branch branch_0.1 master creates branch_0.1 branch from Master Branch Master
git branch-m branch_0.1 branch_1.0 rename branch_0.1 to branch_1.0
git checkout branch_1.0/master switch to Branch_1.0/master branch
Du-hs

-----------------------------------------------------------
mkdir WebApp
CD WEBAPP
Git init
Touch README
git add README
Git commit-m ' first commit '
git remote add origin [email protected]:d Aixu/webapp.git
Git push-u Origin Master

Git Common Command Chart

Http://www.cnblogs.com/1-2-3/archive/2010/07/18/git-commands.html

Reference recommendation:

Using version management tools in a Windows environment git

Git command parameters and usage details

Gitref (recommended)

Tutorial

Create a git repository
Initializing the Git repository

mkdir Project # Create a projects directory
CD project # into the project directory
Git init # initializes the Git repository. This command creates a new. Git directory in the current directory to store information about the GIT repository

Initialize Commit

Touch README
git Add. # Add the current directory to the Git repository and use git add-a to add all the changed documents
Git commit-m "Initial commit"
git remote add origin [email Protected]:lugir/repo.git # Set up warehouse

Patching commits (patching the most recent commit without creating a new submission)

git commit--amend-m "commit message."

You can merge and then push when a conflict is committed

Git pull # Get remote repository submission merge with local commit
git Push # Commit

Use someone else's warehouse

git clone Http://path/to/git.git # clone content will be placed in the new directory under the current directory

To upload code back to the warehouse locally

Git push-u Origin Master

View file status using Git status

git status

View Submission Log

Git log # View submission information
git log--pretty=oneline # Displays submission information in a neat single-line format
git log--stat # View submission information and updated files

Git Branch

Git Branch # View branches
Git Branch 6.x-1.x # Add Branch 6.x-1.x
GIT branch Checkout Master # switch to the main branch
git branch-d 6.x-1.x # Delete Branch 6.x-1.x
git push origin:branchname # Delete remote Branch

Git tags

git tag # View Branch
git tag 6.x-1.0 # add Tag 6.x-1.0
Git show 6.x-1.0 # view tag 6.x-1.0 information
git tag-a 6.x-1.0 965e066 # for previously submitted information record 965e066 plus tag
git push--tags # with tag information on commit
Git push origin:/refs/tags/tagname # Delete remote tag

Exporting items from a git repository

Git archive--format tar--output/path/to/file.tar Master # Package Master in tar format to specified file

Some basic rules for using Git:
When you want to commit/submit a patch:

      • Use Git diff--check to check that there are no extra blanks in the end of the line
      • Each commit changes only one thing. If a document has multiple changes, use git add--patch to select only some of the changes in the document to enter the stage
      • Write the commit message clearly

Git common Commands and tutorials

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.