1. Getting Started
User Information
Configure your personal user name and email address. These two configurations are important, and each time Git commits, it references these two messages, stating who submitted the update, so it will be permanently included in the history along with the update:
$ git config--global user.name "Youname"
$ git config--global user.email "[email protected]"
If you use the --global option, the changed profile is the one located in your home directory (see figure 1), and all of your projects will default to the user information configured here. If you want to use a different name or email in a particular project, just remove the --global option to reconfigure it, and the new settings are saved in the . Git/config file for the current project.
Figure 1
2.GIT Foundation
View configuration information
View existing configuration information
$ git config--list
$ git config-l
Get help
For example, to get help for the config command
$ git help config
$ git config--help
Initializing a new warehouse
$ git init
After initialization, a directory named. Git appears in the current directory, and all of the data and resources that git needs are stored in this directory. At the moment, however, all of the files and directories are initialized in accordance with the existing structural framework, but we have not started to track any of the files in the management project.
If there are several files in the current directory that you want to include in version control, you need to first tell Git to start tracking the files with the git add command and then commit:
Trace files: (add files to the staging area)
$ git Add readme.txt
Track All Files
$ git Add.
Submit Updates
$ git commit-m "first version"
Upload (push) to GitHub
$ GIT push origin master
Cloning from an existing warehouse
$ git clone git://github.com/youname/project.git
$ git clone [email protected]: Youname/project.git
$ git clone https://github.com/youname/project.git
Check the current file status
$ git status
Create a. gitignore file
$ touch. Gitignore
View content that has not been staged after the modification
$ git diff
Remove files from
$ git RM readme.txt
Renaming files
$ git mv oldname.txt newname.txt
View commit History
$ git log
Cancel Staging
$ git reset HEAD. gitignore
Add remote repositories (remote repositories must be built on GitHub first )
$ git remote add [shortname] [url]
Instance:
$ git Remote add origin [email protected]:youname/yourrepo.git
Push Data to Warehouse
$ git push [remote-name] [Branch-name]
If you want to push the local master branch to the origin server (again, the clone operation will automatically use the default Master and Origin names), you can run the following command:
$ GIT push origin master
Fetching data from a remote repository
$ git fetch [remote-name]
If the remote repository server is migrated, or if the original clone image is no longer in use, or if a participant no longer contributes the code, the remote repository needs to be removed
Removal of remote repositories
$ git Remote RM origin
Remote repository renaming ( named here is the ShortName in the Add remote repository above )
$ git Remote rename Origin origin2
Auto-complete
When you press the TAB key after you enter a command, you'll see a list of all the available command suggestions that match:
$ git co<tab>
3.GIT Branch
Create a branch named "testing"
$ git Branch Testing
Switch to "testing" Branch ( default to Master Branch )
$ git checkout Testing
New and switch to this branch
$ git checkout-b iss53
This command is equivalent to performing the following two commands
$ git Branch iss53
$ git checkout iss53
Delete Hotfix Branch (if the branch has not been merged, it will prompt for an error because it will lose data)
$ git branch-d Hotfix
Force Delete Hotfix Branch (Force delete without prompting for errors)
$ git branch-d Hotfix
merging iss53 Branch (switch first to Master Branch)
$ git Checkout Master
$ git Merge iss53
View all current branches
$ git Branch
View information for the last commit object in each branch
$ git branch-v
view the branches that have been merged with the current branch (the merged check out can be deleted)
$ git Branch--merge
View branches that are not merged with the current branch
$ git Branch--no-merged
Synchronizing remote server data to a local
$ GIT fetch origin
Download data from a newly added remote repository
$ git remote add teamone git://git.team1.ourcompany.com
$ git fetch teamone
Differentiate a new branch ( using this command will download the latest version of Master from the server , so if the current local version is not up-to-date, the new branch and local branch will be different )
$ git checkout-b test1 origin/master
If you use this new branch for git pushandmerge, a new branch with the same name will be created in the remote repository .
Ways to delete this branch
$ git push origin:test1
Test1: Based on successive commits (only one C3) following the current branch (that is, the branch to be Rebase), a series of file patches are generated, and then the last Commit object (C4) of the base branch (that is, the Trunk branch master) is the new starting point, Apply the previously prepared patch file one at a time and generate a new merge Commit object (C3 '), overwriting the Test1 commit history, making it a direct downstream of the master branch
The picture repeats the changes made in the C3 to the C4 .
Branching: test1 branches to Master Master Branch
$ git checkout test1
$ git rebase Master
Another method, the direct diffraction, no need to switch to test1 first
$ git rebase master test1
Fast forward Master Branch
$ git Checkout Master
$ git Merge Client
Rebase: Once the commit object in the branch is published to the public repository, do not rebase the branch.
Common basic commands for Git