git use commands

Source: Internet
Author: User
Tags git commands

1 Viewing remote branches
123456789101112131415 $ git branch -a* br-2.1.2.2 master remotes/origin/HEAD -> origin/master remotes/origin/br-2.1.2.1 remotes/origin/br-2.1.2.2 remotes/origin/br-2.1.3remotes/origin/master
2 Viewing local branches
12345 $ git branch* br-2.1.2.2master
3 Creating a branch
1234567891011 [email protected] /f/ggg/jingwei(br-2.1.2.2) $ git branch test $ git branch * br-2.1.2.2 mastertest
4 switching branches to test
1234567891011121314151617181920212223242526272829 [email protected] /f/ggg/jingwei (br-2.1.2.2)$ git branch* br-2.1.2.2mastertest[email protected] /f/ggg/jingwei (br-2.1.2.2)$ git checkout test M jingwei-server/src/main/java/com/taobao/jingwei/server/service/cmd/GetCustomerTarCmd.javaM jingwei-server/src/main/java/com/taobao/jingwei/server/util/ServerUtil.javaSwitched to branch ‘test‘[email protected] /f/ggg/jingwei (test)$ git branch br-2.1.2.2mastertest
5 Delete local branch git branch-d xxxxx
12345678910111213141516171819202122232425262728293031 $ git checkout br-2.1.2.2M jingwei-server/src/main/java/com/taobao/jingwei/server/service/cmd/GetCustomerTarCmd.javaM jingwei-server/src/main/java/com/taobao/jingwei/server/util/ServerUtil.java Switched to branch ‘br-2.1.2.2‘[email protected] /f/ggg/jingwei (br-2.1.2.2)$ git br* br-2.1.2.2mastertest[email protected] /f/ggg/jingwei (br-2.1.2.2)$ git br -d test Deleted branch test (was 17d28d9).[email protected] /f/ggg/jingwei (br-2.1.2.2)$ git br* br-2.1.2.2master
6 view local and remote branch-a. The front with the * number represents the branch where your current working directory is located
12345678910111213141516171819 [email protected] /f/ggg/jingwei (test)$ git branch -abr-2.1.2.2mastertestremotes/origin/HEAD -> origin/masterremotes/origin/br-2.1.2.1remotes/origin/br-2.1.2.2 remotes/origin/br-2.1.3remotes/origin/master

Add some common commands below.

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) operation 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 submit

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

The above written half, found that someone on the net summed up very well, the copy came directly. Website: http://www.cnblogs.com/1-2-3/archive/2010/07/18/git-commands.html

git use commands

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.