Home Development Tools git How to use Git

How to use Git

Jan 21, 2021 am 09:51 AM

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
Copy after login

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 of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1252
29
C# Tutorial
1226
24
How to update code in git How to update code in git Apr 17, 2025 pm 04:45 PM

Steps to update git code: Check out code: git clone https://github.com/username/repo.git Get the latest changes: git fetch merge changes: git merge origin/master push changes (optional): git push origin master

How to download git projects to local How to download git projects to local Apr 17, 2025 pm 04:36 PM

To download projects locally via Git, follow these steps: Install Git. Navigate to the project directory. cloning the remote repository using the following command: git clone https://github.com/username/repository-name.git

How to generate ssh keys in git How to generate ssh keys in git Apr 17, 2025 pm 01:36 PM

In order to securely connect to a remote Git server, an SSH key containing both public and private keys needs to be generated. The steps to generate an SSH key are as follows: Open the terminal and enter the command ssh-keygen -t rsa -b 4096. Select the key saving location. Enter a password phrase to protect the private key. Copy the public key to the remote server. Save the private key properly because it is the credentials for accessing the account.

How to return after git submission How to return after git submission Apr 17, 2025 pm 01:06 PM

To fall back a Git commit, you can use the git reset --hard HEAD~N command, where N represents the number of commits to fallback. The detailed steps include: Determine the number of commits to be rolled back. Use the --hard option to force a fallback. Execute the command to fall back to the specified commit.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

What to do if the git download is not active What to do if the git download is not active Apr 17, 2025 pm 04:54 PM

Resolve: When Git download speed is slow, you can take the following steps: Check the network connection and try to switch the connection method. Optimize Git configuration: Increase the POST buffer size (git config --global http.postBuffer 524288000), and reduce the low-speed limit (git config --global http.lowSpeedLimit 1000). Use a Git proxy (such as git-proxy or git-lfs-proxy). Try using a different Git client (such as Sourcetree or Github Desktop). Check for fire protection

Git vs. GitHub: Version Control and Code Hosting Git vs. GitHub: Version Control and Code Hosting Apr 11, 2025 am 11:33 AM

Git is a version control system, and GitHub is a Git-based code hosting platform. Git is used to manage code versions and supports local operations; GitHub provides online collaboration tools such as Issue tracking and PullRequest.

How to merge code in git How to merge code in git Apr 17, 2025 pm 04:39 PM

Git code merge process: Pull the latest changes to avoid conflicts. Switch to the branch you want to merge. Initiate a merge, specifying the branch to merge. Resolve merge conflicts (if any). Staging and commit merge, providing commit message.

See all articles