git common operations

Git
XP system installation Git-2.6.1-32-bit.exe
WIN7 installation Git-1.9.4-preview20140929.exe



//git installation
$ git config --global user.name "XXXXX"
The user name when the code is submitted, and The GITLAB registered user name is recommended to be consistent
$ git config --global user.email [email protected]
The user's email address when the code is submitted is consistent with the GITLAB registration information suggestion

$ git config --global core.autocrlf false
Code submission And do not do the conversion of CRLF (Windows carriage return) and LF (Linux carriage return) when checking out, and it is recommended to keep the Linux file format when writing code.


$ ssh-keygen
generates the ssh key, and generates two files id_rsa, id_rsa.pub is the private key and the public key, which are generally located in the .ssh directory under the folder of your own login user name corresponding to C:\Documents and Settings,
such as C :\Documents and Settings\Administrator\.ssh.


Associate the remote library
git remote add origin [email protected]:xxxx/my-test-project.git
All contents of the local library are pushed to the remote library When the master branch is pushed for
the first time, the -u parameter is added,
Git will not only push the content of the local master branch to the new remote master branch, but also associate the local master branch with the remote master branch, which can simplify the command
git push -u origin master in future pushes or pulls

Clone remote library
git clone [email protected]:xxxx/my-test-project.git

git clone ssh://[email protected]:29418/code


View remote library
$ git remote
$ git remote -v

push branch attention is to push the local master branch to the remote origin master branch
$ git push <remote host name> <local branch name>:<remote branch name>
$ git push origin master
$ git push origin dev


to create a branch
$ git checkout -b dev


$ git branch dev
$ git checkout dev

View branch
$ git branch


//Merge branch Note here are both sides, checkout master first, then merge dev into master branch
$ git checkout master
$ git merge dev

Indicates that Fast forward is disabled:
$ git merge --no-ff -m "merge with no-ff" yu


//delete branch
$ git branch -d dev


//establish the association between local branch and remote branch, use
git branch --set -upstream branch-name origin/branch-name;
$ git branch --set-upstream dev origin/dev



add new files, submit and modify
$ git add readme.txt
$ git commit -m "branch test"

// will all the current directory The modified and added files and directories are submitted to the staging area
git add .

//git add -A: [<path>] means to modify or delete files and all untracted files in all tracked files in <path> information is added to the index library. Omit <path> to indicate ., the current directory.
git add -A


//Revocation add
git reset head .


//View status
$ git status


//The function of the git pull command is to retrieve the update of a branch of the remote host, and then merge it with the specified local branch. Its full format is slightly more complicated
$ git pull <remote hostname> <remote branch name>:<local branch name>
git pull origin master


//fetch is equivalent to pull
git fetch origin master
git log -p master..origin/master
git merge origin/master

code modification steps
Create a branch
$ git checkout -b yu

//
git checkout yu

git add
.git commit -m "add by yhj"

git checkout master
git merge --no-ff -m "merge with no-ff by yhj" yu


git pull origin master
git push origin master

git checkout yu


//Merge the contents of the master branch into yu branch
git checkout yu
git merge --no-ff -m "merge to yu with no-ff by yhj" master

//
git checkout master
git pull origin master
git checkout yu
git merge --no-ff -m "merge to yu with no-ff by yhj" master



//Filter files
locally git config --global core.excludesfile F:/.gitignoreglobal

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326771705&siteId=291194637