Home>Article>Development Tools> How to use Git

How to use Git

coldplay.xixi
coldplay.xixi forward
2021-01-21 09:51:29 2939browse

How to use Git

Recommended (free):Git usage tutorial

  1. Set up Git
    First Go to the Git official website to download Git, and finally get Git Bash Git Cmd Git GUI
    Open Git Bash, enter your username and email address
    $ git config --global user.name "jiangjievior"
    $ git config - -global user.email “1534410005@qq.com”

  2. Use Git
    Create a folder for Git work github
    Open Git Cmd and switch to this directory , enter
    git init
    to create the file hello.txt in the folder
    means to initialize the folder as the working folder of Git
    add the file to Git
    git add hello.txt
    Indicate notes for adding files this time
    git commit -m "Added hello.txt"
    After modifying the file, add new files again and add notes
    git add hello.txt
    git commit -m "A sentence was added to hello.txt"
    View the records of each file added in the past
    git log
    Finally get each record, you can return the previous records through the specified id after commit File
    commit 88d885c21216cbedacb1692e08d51afa6d4e32a7 (HEAD -> master)
    Author: yepdlpc mattbaisteins@gmail.com
    Date: Wed Dec 19 20:13:22 2018 0800

    Add in hello.txt One sentence

commit ec4652d5d0b8662fc8730d64b42341d1c363a442
Author: yepdlpc mattbaisteins@gmail.com
Date: Wed Dec 19 20:11:42 2018 0800

添加了hello.txt

Return the file to the previously specified version (1 here represents the return to the last time)
git reset --hard HEAD^1
Return to the previously specified file through the beginning of part of the id code
git reset --hard 88d885
View every previous modification to the file
git reflog
Git Hub usage tutorial
1. Create public and private keys
Click on GIt bash to open the command window
Enter: ssh- keygen -t rsa -C "name", "email", name is the user name, Email is your email
For example:
$ ssh-keygen -t rsa -C "jiangjievior", "1534410005@qq. com”
2. File upload and download
Create a folder with the same name as the warehouse in Git Hub in the computer directory, and use Git commands to bind to upload and download

  1. Upload local files to Git Hub repository
    Switch Git Cmd to the newly created directory and set the directory as Git repository
    git init
    Upload the file to Git repository and add remark information (git add * can be used once Add all files)
    git add hello.txt
    git commit -m "first commit"
    If the next step is unsuccessful, perform the following and delete the existing association in advance
    git remote rm origin

Connect the local Git repository with the remote Git Hub repository
git remote add origin git@github.com:MachinePlay/Gittest.git
git@github.com:MachinePlay/Gittest. git is the SSH code of the warehouse in Git Hub, as shown below:

Push all the contents of the local Git warehouse to the remote Git Hub warehouse
git push -u origin master
Since the remote library is Empty. When we pushed the master branch for the first time, we added the -u parameter. Git will not only push the contents of the local master branch to the remote new master branch, but also associate the local master branch with the remote master branch. , the commands can be simplified when pushing or pulling in the future.

After that, you can use git add git commit-m
git push origin master

The process is as follows:
git init
git remote rm origin (maybe not needed)
git remote add origin git@github.com:jiangjievior/python-.git
git status (view uploaded files)
git add hello.txt (or git add *)
git commit - m “first commit”
git push -u origin master

  1. Download the Git Hub warehouse file to the local
    First use Git Cmd to switch to a local directory to receive the download File
    By entering the Git Hub warehouse SSH code, use the following statement to upload the file to the Git Hub warehouse
    git clone git@github.com:smuyyh/BookReader.git

The above is the detailed content of How to use Git. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete