Five steps to master the basic development and usage commands of Git, and five steps to master git commands

Source: Internet
Author: User
Tags git commands

Five steps to master the basic development and usage commands of Git, and five steps to master git commands
Step 1: set global variables:

git config --global user.name "gang.li"git config --global user.email "ligang@ptthink.com"
Step 2: Initialize the repository and push it to the remote repository (if this step is performed for the first push, otherwise skip this step ):
/* Create a project folder and initialize the repository */mkdir testcd testgit init/* to add the README file, submit */touch READMEgit add READMEgit commit-m'first commit '/* to associate the remote repository and push */git remote add origin git @ git. *. jp: gitlab/test. gitgit push-u origin master
Step 3: Clone the remote host project to the local machine and create the corresponding branch
git clone git@git.*.jp:gitlab/test.gitgit checkout -b developgit branch --set-upstream develop origin/develop(git branch --set-upstream-to=origin/develop develop)
Step 4: add, delete, and push to the specified remote Branch
/* Delete the file (the local git rm file will not be deleted) */git rm-rf targetgit add. git commit-m "claer" git push origin develop
Step 5: merge branches:
/* View all branches */git branch-r/-a/* merge develop to master branch */git checkout mastergit merge -- no-ff developgit push origin master
By default, Git runs fast-farward merge to direct the Master branch to the Develop branch. After the -- no-ff parameter is used, the merge operation is executed normally and a new node is generated on the Master branch.
1. clone a version library from a remote host (1) git clone <version library URL>
(2) When cloning the version library, the remote host used is automatically named as Origin by Git. If you want to use another host name, use-o to specify:
Git clone-o jQuery https://github.com/jquery/jquery.git
2. Remote Host management for ease of management, Git requires that a host name be specified for each remote host.
(1) list all remote hosts: git remote
(2) view the remote host URL: git remote-v
(3) view the host details: git remote show origin
(4) add a remote host: git remote add <Host Name> <URL>
(5) Delete the remote host: git remote rm <Host Name>
(6) rename the remote host: git remote rename <Host Name> <website>
Iii. Local retrieval (1) retrieve all local data, not automatically merged: git fetch <Remote Host Name> <branch name>
(2) retrieve updates from a branch of the remote host and merge them with the specified local branch: git pull <Remote Host Name> <remote branch name >:< local branch name>
Retrieve the next branch of the origin host and merge it with the local master branch: git pull origin next: master
If the remote branch is merged with the current branch, the part after the colon can be omitted: git pull origin next
(2) manually establish a tracing relationship: git branch -- set-upstream master origin/next
PS: git pull origin next is equivalent to: git fetch origin git merge origin/next
4. push to remote (1) Update the local branch to the remote host: git push <Remote Host Name> <local branch name>: <remote branch name>
(2) If the remote branch name is omitted, the local branch is pushed to a remote branch with a "tracing relationship" (usually with the same name). If the remote branch does not exist, it will be created: git push origin develop
(3) If the local branch name is omitted, the specified remote branch is deleted, because it is equivalent to pushing an empty local branch to the remote Branch:
Git push origin: master
Equivalent to: git push origin -- delete master (delete the master branch of the origin HOST: git push
(4) If the current branch has only one tracing branch, the host name can be omitted: git push
Note that the branch push order is written as <source>: <destination>, So git pull is <remote branch >:< local branch>, while git push is <local branch>: <remote branch>.
5. Other commands (1) gitk: Open the graphical interface
(2) git -- help

(3) git merge -- help


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.