GIT and GitHub

Time:2020-8-1

Use of GIT

Git operation command

Git configuration

Git — version / / display version

git –config –global user.name “User name” / / set user name

git –config –global user.email “Mailbox” / / set mailbox

[note]: — local (only valid for warehouses); — global (valid for all warehouses of logged in users); — system (valid for all users of the system)

Note: the default is local if the parameter is not written

Git config — List — global / / display config configuration

[note]: git config — List — local; git config — List — system

Clear / / clear screen

Git create local warehouse

After entering git Bash

Use the CD file name to find the folder that you want to be the repository (CD… / return to the previous level)

When you find the folder,

Git init / / create local warehouse

Git then creates a hidden. Git folder in that folder

LS – LA / / view all the files in this warehouse (similar to Linux command)

Git init XXX / / XXX is the name of the folder. A new warehouse named XXX is created in the current folder

Add documents to local warehouse

Git log / / view the version history of GIT version library

Git add XXX / / enter the file XXX into the temporary storage area, which is not a version library

Git status / / view the submission. If the font is red, it means that there is no commit after modification

Git commit – M “XXX” / / put all the files in the temporary storage area into the version library, where XXX is a comment and cannot be omitted

touch XXXX.XXX //Create XXXX.XXX This file is not managed

vim XXX.XXX //Editor XXXX.XXX File (: WQ exit edit mode)

The concept of version Library

Version library, also known as warehouse (database), can be simply understood as a directory. In this directory, all files can be managed by GIT. Git can track the modification and deletion of each file, so that the history can be traced at any time or “restored” in the future.

1. Remote warehouse: equipped with special server, the warehouse is established for sharing by many people

2. Local warehouse: a warehouse configured on one’s own computer for personal use

GIT and GitHub

Create a remote warehouse -“ github.com “

Create a repository on GitHub

Git remote warehouse push

  1. Use remote instruction to add to remote warehouse: git remote add name URL / / name represents the name of remote warehouse, and URL represents the address of remote warehouse. Name can be omitted (default origin)

    [note]: use git remote – V to check whether the connection is established

  2. Use the push command to push the local warehouse to the remote warehouse: git push – U origin master / / the first origin refers to the name, and the later refers to the master branch. Fixed writing

    Note: in the following push, the – U parameter is not required

[note]: the pushed warehouse cannot have sub warehouses;

Note: if the connection is wrong, use the GIT remote RM origin command to restart

Add git’s READ.md file

touch README.md //Create a readme file

git status

git add README.md //Submit staging area

git status

git commit -m “add README.md”

git status

git log

Git remote – V / / view it. If it is not created, push it again

Git push / / enter the account password. There are two situations: the first is the email address and password (a new window pops up), the second is the address and password (operate in the black box)

Git remote warehouse update

If the local warehouse is uploaded without updating, an error will be reported; refer to 008.png

Specific reason: because there is a file that has not been updated locally, but the file with the same name in the remote warehouse is updated, an error will be reported if the file is pushed directly.

[note] if everything is up to date, everything up to date will be returned

Solution: use Ctrl + C to terminate the current command; use git pull to pull the latest file

git pull –rebase origin master。

[prompt] if more than one person works at the same time, everyone will push the modification to the remote warehouse after the operation, so it is necessary to form a habit. Pull before push

Git clones from remote repository

In the actual process, there are often remote warehouses and then local warehouses.

Git clone remote repository URL / / if it is a private remote repository, you may enter a password

Git remote – V / / view remote warehouse

Git skills

1. Rename the file:

The name can be changed manually;

It can also be usedcommandRename: Clone first and create the file with the old name( readme.txt )->Add to staging area > put into warehouse > purpose: change old name( readme.txt )Success( readme.md )->mv readme.txt readme.md (MV old name new name) – > delete old file (GIT RM readmd.txt )->Add a new file (GIT add read.md )->Git commit – M “XXX” submit version Library (this has not been submitted to the remote warehouse) – > push (please consider carefully)

Version rollback method:
Git reset — hard version number (a string of characters after commit) / / be careful when rolling back the version. However, the remote warehouse is not changed at this time because there is no push.

/ / the new name can be changed directly

2. Delete the file correctly

​ rm readme.md

​ git add read.md

Easy way: git RM files to delete

3. Specify files that do not need git Management:

The. Gitignore file tells git that the pointing file can be ignored when pushing, and the ignore rule needs to be specified on each line.

[note] “.”. Indicates hidden files.

eg:

*. Log / / ignore all. Log files

* * / foo / / ignore / foo, a / foo, a / B / foo, etc

A / * * / B / / ignore a / B, a / X / B, a / X / Y / B, etc

​ .DS_ Store / / ignore.ds_ Store file

Bin / / / ignore all files in bin directory, but do not ignore bin files