How to use gitee and githup? Here is a nanny level step full solution!

What is git?

Git is a free and open source distributed version control system (technology for managing multi person collaborative development projects)

What is a distributed version control system?

  • Users can view all the files uploaded to git locally [git clone / git pull can get the files on git]

  • Users can submit locally even if they are offline. Networking is required only when push is pushed to a remote server

  • Each user saves the historical version, so as long as one user device is OK, the data can be recovered

What are the four working areas of git?

  • Workspace: the workspace is the place where the project code is usually stored

  • index /stage: the temporary storage area is used to temporarily store changed files. In fact, it is just a file to save the list information of files to be submitted

  • repository: the warehouse area (local warehouse) is the location where data can be safely stored. There are data submitted to all versions, where HEAD points to the latest version put into the warehouse (ref:cefs/heads/master: main branch)

  • Remote: remote warehouse, a server hosting code, can be simply regarded as a computer in your project team for remote data exchange

How does git work?

1. Add and modify files in the working directory (UserMapper.xml)

2. Put the files requiring version management into the temporary storage area (git add)

3. Submit the files in the staging area to the git warehouse (git commit)

4. Submit the file to the remote warehouse [server hosting code] (git push)

5. Pull the file and save it to the local warehouse (your own computer) (git clone or git pull)

What are the three interfaces for git?

  • git bash: unix and linux style command line, most used and most used

    Personal suggestion: if your computer has downloaded git software, when using git, you can first find your own warehouse (folder) dedicated to saving git files, then right-click and click Git Bash Here

  • git cmd: Windows style command (cls)

  • git gui: git in graphical interface. It is not recommended for beginners. Try to be familiar with commands first

If I'm a novice, how can I use git?

1. First, you need to open an account in gitee or github (if you are a novice, it is recommended that you use gitee first), and then create your own warehouse. If you have a team, you can fork your teammate's warehouse. Once the warehouse is built, you will have your own website

2. Clone remote warehouse to local:

git clone The website of your warehouse (as shown in the figure, just copy it)       #First use

3 * in order to use git more conveniently and quickly, we can establish shortcuts through alias mapping (remote)

git remote -v    #View alias mappings

git remote add origin1 Website 1     #The next time I want to use URL 1, typing origin1 means the same

git remote add origin2 Website 2     #If you often use other people's websites, you can also copy other people's websites and establish shortcuts

git remote remove origin1       #Delete the alias mapping origin1

4 * if you have completed the above steps and want to modify your warehouse for the second time, you can pull it by pull

git pull origin1 master          #Merge the remote master branch into the current local master branch (equivalent to refreshing and synchronizing the modified content of your remote warehouse)

5. Enter the folder, find the file or create a new file, add, delete, modify and check it

ls cd mikdir ...      #The operation is roughly the same as that of Linux

6. After modifying your file, you can put the file in the index /stage first

git add File or folder name

git add .              #Add all files in the current directory to the cache

7. Submit your files to the local repository

git commit -m "Description information"File or folder name

8. Submit your newly modified or added content to remote warehouse

git push Warehouse website master     #Push all updates of the local branch to the remote warehouse master branch

git push origin1 master     #Clever use of alias mapping

git common command summary!

git checkout -b bra     #If you need to develop another project, use this command to create a new branch
						#At this time, the (bra) branch is displayed on your command line, not the master
						
git status              #View warehouse status
git status -s           #View the current workspace, staging area changes, and summary information
git status  --show-stash       #Query whether there is a stash (temporary file) in the workspace
   	&: When you forget whether you have added the code file to the staging area or submitted it to the local warehouse, you can use it git status
    
git log                  #View commit history or commit log
git log --oneline        #View submission history in thin mode
git log -p <file>        #View the submission history of the specified file
git blame <file>         #View the submission history of the specified file as a list

git diff                 #Displays the difference between the cache and the workspace
git diff filepath   filepath            #Comparison difference between workspace and staging area in path file
git diff HEAD filepath                  #Comparison difference between workspace and head
git diff branchName filepath            #Comparison difference between files in the current branch and files in the branchName branch
git diff commitId filepath              #Comparison difference with a certain submission (difference in modification of reference documents)
git diff zjh.py                         #Compare ZJH What have we modified in the file py

git branch                              #View branch
git branch name                         #Create branch
git checkout name                       #Switch branch
git checkout –b name                    #Create + switch branch
git merge name                          #Merge a branch to the current branch
git branch –d name                      #Delete branch

git checkout [file]                     #Discard a file
git checkout .                          #Discard all files
git reset --hard 77sdbbfjfs(Version number)      #Restore the deleted content (by viewing the log)

Special note:

**This article refers to the articles of the following two great gods. You can click in and have a look. Maybe you want something!
Learn Git in an hour
Programmers must: git command all-round learning

Keywords: Linux git github

Added by hamzatki on Fri, 24 Dec 2021 03:01:03 +0200