search
How to use GitJan 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

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. If there is any infringement, please contact admin@php.cn delete
How to use git management tools for complete usage of git management toolsHow to use git management tools for complete usage of git management toolsMar 06, 2025 pm 01:32 PM

This article provides a guide to Git management, covering GUI tools (Sourcetree, GitKraken, etc.), essential commands (git init, git clone, git add, git commit, etc.), branch management best practices (feature branches, pull requests), and merge con

How to push the specified commitHow to push the specified commitMar 06, 2025 pm 01:39 PM

This guide explains how to push a single Git commit to a remote branch. It details using a temporary branch to isolate the commit, pushing this branch to the remote, and then optionally deleting the temporary branch. This method avoids conflicts and

How to view commit contentsHow to view commit contentsMar 06, 2025 pm 01:41 PM

This article details methods for viewing Git commit content. It focuses on using git show to display commit messages, author info, and changes (diffs), git log -p for multiple commits' diffs, and cautions against directly checking out commits. Alt

The difference between commit and push of gitThe difference between commit and push of gitMar 06, 2025 pm 01:37 PM

This article explains the difference between Git's commit and push commands. git commit saves changes locally, while git push uploads these committed changes to a remote repository. The article highlights the importance of understanding this distin

How to solve the failure of git commit submissionHow to solve the failure of git commit submissionMar 06, 2025 pm 01:38 PM

This article addresses common Git commit failures. It details troubleshooting steps for issues like untracked files, unstaged changes, merge conflicts, and pre-commit hooks. Solutions and preventative measures are provided to ensure smoother Git wo

The difference between add and commit of gitThe difference between add and commit of gitMar 06, 2025 pm 01:35 PM

This article explains the distinct roles of git add and git commit in Git. git add stages changes, preparing them for inclusion in the next commit, while git commit saves the staged changes to the repository's history. This two-step process enables

How to use git management tools Tutorial for using git management tools for beginnersHow to use git management tools Tutorial for using git management tools for beginnersMar 06, 2025 pm 01:33 PM

This beginner's guide introduces Git, a version control system. It covers basic commands (init, add, commit, status, log, branch, checkout, merge, push, pull) and resolving merge conflicts. Best practices for efficient Git use, including clear comm

What is git code management tool? What is git code management tool?What is git code management tool? What is git code management tool?Mar 06, 2025 pm 01:31 PM

This article introduces Git, a distributed version control system. It highlights Git's advantages over centralized systems, such as offline capabilities and efficient branching/merging for enhanced collaboration. The article also details learning r

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft