Git usage notes

Source: Internet
Author: User

Git usage notes
Git has a tool called git config that allows you to get and set configuration variables. These variables can control the appearance and operations of Git. 1. storage location of the configuration file these variables can be stored in three different locations:/etc/gitconfig file: contains values suitable for all users and all libraries of the system. If you pass the parameter option '-- system' to git config, it will explicitly read and write the file. ~ /. Gitconfig file: specific to your user. You can enable Git to read or write this specific file by passing the -- global option. Config File (that is,. git/config) in the git Directory: No matter what library you are currently using, it points to this single library. Each level overrides the value of the previous level. Therefore, the value in. git/config overwrites the same value in/etc/gitconfig. 2. Configure your username and password. The first thing you need to do after installing Git is to set your user name and email address. This is very important because this information is used every time a Git commit is made. It is always embedded in your commit: 1 $ git config -- global user. name 'xxxxxxx' 2 $ git config -- global user. email '[email protected]' is repeated. You only need to perform this setting once. If you pass the -- global option, Git will always use this information to process all your operations in the system. If you want to use different names or e-mail addresses in a specific project, you can run the command in the project instead of the -- global option. 1 $ git config user. name 'your username' 2 $ git config user. e-mail 'your mailbox 'git usage practices: Common commands such as creating an environment, successfully adding, submitting, pushing, and updating. 1 # environment 2 git -- version 3 git version 1.7.1 4 pwd 5/data1/home/xxxxxxx/img 6 # create a working directory 7 mkdir liupengGitTest 8 cd liupengGitTest/9 # initialize the working directory 10 git init11 # Set the user information of the current version library 12 git config user. name 'xxxxxxxx' 13 git config user. email '[email protected] '14 # test 15 touch README16 # add file 17 git add README 18 # submit the modified file 19 git commit-m'first commit' 20 # add remote repository 21 # create 22 git remote add on the git service site Origin ssh: // xxxxxxx/mytest. git23 # push local files to remote repository 24 git push-u origin master25 # update the local repository. If you need to modify the file, update it first, prevent conflict 26 # You can also use git fetch27 git pull git practice advanced to create branch and merge branch create branch 1 $ pwd 2/data1/home/xxxxxxx/liupengGitTest 3 # view the current Branch 4 $ git branch 5 * master 6 # create a branch dev, switch the branch to dev 7 # git checkout-B dev. You can use git branch dev in another way; git checkout dev 8 $ git checkout-B dev 9 Switched to a new branch 'dev' 10 $ git Branch 11 * dev12 master13 $ ll14 total 415-rw-r -- 1 xxxxxxx domain ^ users 110 Sep 1 README merge branch 1 $ git branch 2 * dev 3 master 4 $ touch addtxt 5 $ git add addtxt 6 $ git commit-m' branch dev add a new file '7 [dev 78dd0f9] branch dev add a new file 8 0 files changed, 0 insertions (+), 0 deletions (-) 9 create mode 100644 addtxt10 $ git status11 # On branch dev12 nothing to commit (worki Ng directory clean) 13 # dev branch two files 14 $ ll15 total 416-rw-r -- 1 xxxxxxx domain ^ users 0 Sep 1 addtxt17-rw-r -- 1 xxxxxxx domain ^ users 110 Sep 1 README18 $ git checkout master19 Switched to branch 'master' 20 # master branch a file 21 $ ll22 total 423-rw-r -- 1 xxxxxxx domain ^ users 110 Sep 1 README24 # merge Branch 25 $ git merge dev26 Updating a279cb0 .. 78dd0f927 Fast-forward28 0 files change D, 0 insertions (+), 0 deletions (-) 29 create mode 100644 addtxt30 $ git branch31 dev32 * master33 # The master branch has two files! 34 $ ll35 total 436-rw-r -- 1 xxxxxxx domain ^ users 0 Sep 1 31 addtxt37-rw-r -- 1 xxxxxxx domain ^ users 110 Sep 1 01 README38 # push to remote server git push origin master do not u, if the current branch has a tracing relationship with multiple hosts, you can use the-u option to specify a default host. In this way, you can use git push without adding any parameters. 39 $ git push-u origin master40 Counting objects: 4, done.41 Compressing objects: 100% (2/2), done.42 Writing objects: 100% (3/3), 275 bytes, done.43 Total 3 (delta 0), reused 0 (delta 0) 44 To ssh: // xxxxxxx/mytest. git45 a279cb0 .. 78dd0f9 master-> master46 Branch master set up to track remote branch master from origin.47 $ git status48 # On branch master49 nothing to commit (working directory clean) 50 $

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.