Common Git Operating Commands

Common commands

git --version       View version information
git config --global user.name = "name"          Configure User Name
git config --global user.email = "xxx@xxx.com"  Configure user mailbox

cd: Switch the working directory. change directory
pwd: Print the working directory. print work directory
ls: View the contents of the specified directory, not the current directory. list
    -a: View everything, including hidden files(with.Initial document)
    -l: List display details
clear: Clear screen display, quick operation: ctrl + L

git init                    #Create Version Library
git add filename             #Add the specified file, add file modification from workspace to temporary area
git add .                   #Add all files
git commit -m "Submission of information"      #Submission of records
git commit -a -m "Submission of information"   #Submit records (all modifications)
    -a: Submitting all changes is equivalent to executing them. git add .
git status                  #View status
    -s                      #View short status information
git log                     #View the submission log
    --oneline               #Show short description information in one line
git checkout filename        #Recovering Workspace from Version Library
git reset HEAD filename      #Restore data from temporary storage area to workspace

git remote add origin url   #Add a remote warehouse address
git push -u origin master   #Push the local mater branch to the master branch of the origin repository

git clone url               #Cloning a Version Library from a Remote Warehouse

File Ignorance

  • Not all files need to be included in version management, such as logs generated during operation, caching, etc.
  • Specific files can be ignored and information written in. gitignore
  • Ignore rules
# Represents comments, changes will be ignored, empty lines will be ignored
 Test.txt ignores the specified file test.txt
 abc / Ignore abc files
 / abc only ignores abc in the project root directory
 * apk All APK files
 a.apk except a.apk
 * [o a] All. a and. o files
 All log files in the abc/*.log ABC directory will not be searched recursively
 All log files in the abc/**/*.log ABC directory are searched recursively

Branch management

  • Look at the branch:
 git branch         #Look at the local branch, with * indicating the current branch
 git branch -r      #View remote branches
 git branch -a      #View all branches
  • Creating Branches
 Git branch development [branch or submission based] # create branch development
  • Delete branches
 git branch -d develop  #Delete the develop ment branch
  • Switching branch
 git checkout develop   #Switch to the develop ment branch
  • Create and switch branches
 git checkout -b develop        #Create a new branch, develop, and switch to that branch
  • Merging branches
git merge develop       #Merge the develop ment branch to the current branch
  • Consolidation conflict
    Conflict file content
<<<<<<< Purpose branch
echo 1234444;
=======
echo 1233333333;
>>>>>>> Merging branches

Conflict resolution
1. Manual deletion of conflict markers
2. Keep the right content
3. Add (git add.) and submit (git commit)

Project Development

  • master: main branch, mainly for release
  • Development: development branch, keeping up-to-date code normally developed
  • local: Represents the temporary branch when adding functionality locally, created based on development, and finally merged into the development branch
  • Description:
    • Add functional code to the local functional branch and merge the test into the develop ment branch (after which you can delete the able branch)
    • After merging and develop ing the branch, you need to push it to the server, first pull down the latest submissions using git pull
    • If there is a conflict, resubmit it after the conflict and push it to the server

clone from the server only has the main branch, other branches are invisible, the first use needs checkout

git clone https://github.com/JerryCoding/test.git

git checkout develop

ssh login (passwordless login)

  • Need to use public key private key pairs
  • Generating a public-private key pair ssh-keygen will be generated in the ~/.ssh directory (id_rsa, id_rsa.pub)
  • Paste the content of id_rsa.pub public key into the hosted website
  • First use requires identification
  • In the future, it will be possible to push without password.

Working principle

Workspace <=> Temporary <==> Version Library <==> Remote Library

Hosting website

  • github.com
  • git.oschina.net
  • coding.net

Keywords: git ssh github

Added by jhlove on Wed, 19 Jun 2019 00:36:02 +0300