This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

In modern project development, the separation of front and back ends, multi-party collaboration, code version change, code hosting is a big problem, currently the more popular is to use Git and SVN.

Of course, git accounts for more!! Personally, I think Git is convenient and fast. Today, I will learn about Git.

What a,git: code version control tool

Liverpoolfc.tv: git-scm.com/

Download git: git-scm.com/downloads,

If you want to get started using Git quickly, here is a simple guide to getting started with Git.

Git is an open-source, free, distributed version management tool that helps you manage your documentation, code, and project versions

How to use Git

2.1 Installing and downloading Git

Official website installation tutorial: git-scm.com/downloads,

After the download is complete, click next all the time to complete the installation (of course, you can also choose the installation directory to customize the installation to other disks).

Git bash here: git bash here: git bash here: git bash here

2.2 Configuring Accounts

After installation, configure git account information for submitting repositories to a remote (” hosting to the online cloud repository “)

# change YourName to our own username;
# change [email protected] to our own email.
$ git config --global user.name "YourName"
$ git config --global user.email "[email protected]"
Copy the code

Iii. Use steps in the project:

3.1 Creating a Project Directorygit_study

Create a project directory, git_study

mkdir git_study
Copy the code

3.2 Initialize a Git project repository

  • Use the —- command.git init
  • You can also usegit init -yUse the default Git repository template.

3.3 Viewing warehouse Status:

The project folder and internal files currently managed by Git.

git status
Copy the code

3.4 File Configuration To Be Ignored.gitignore

If you want to ignore one or more files that are not managed by Git, you need to create a.gitignore file in your project and write the full name or folder of the ignored file into it.

By creating a.gitignore file that writes and saves files or folders that need to be ignored, these files are ignored when committing git repository operations without logging changes.

touch   .gitignore
vi .gitignore Edit Writes and saves files or folders that need to be ignored
Copy the code

3.5 Added files in the Local Project folder

The first step is to add it to the local project repository,

// Use the command

The full name of the git add fileCopy the code

You can also add all files to your Git project using the command argument. Or –all:

git  add .    
# or
git  add --all
Copy the code

Commit code changes to the local repository

4.1 Submit code to the repository

You first need to commit your added files to git’s “local server.

git  commit  -m "Log"Log requiredCopy the code

4.2 Operations After File Modification

If the added file is modified, perform the add operation first and then commit operation

git add . # git add -A
git commit -m 'logger'
Copy the code

4.3 Viewing Log Information

Of course, there are a number of parameters for us to format the log for easy viewing, details can be found in the official documentation.

git log
Copy the code

4.4 Rolling Back to a Previously Submitted Version:

git  reset --hard "Top six values in the log list"
Copy the code

Five, branch operation

  • View branches:git branch
  • Create a branch:Git Branch Branch name
  • Switch branches:Git Checkout branch name
  • On the masterMerging branchesGit merge branch name(Merge branch to master branch)
git branch -d onebranch  # delete branch from master
Copy the code

6. Remote warehouse

Github is a platform for hosting repositories (code, etc.), similar to gitee Domestic stability/GitLab company

Git service providers can upload projects to GitHub through Git and manage our projects through GitHub. Most of our work uses gitLab and the code hosting platform set up by the company itself. Here’s a free github demo:

Clone github project locally by using the following command:

git  clone  https://github.com/yourgithub-name/<yourproject-name>.git 
Copy the code

After modifying the project locally, push the new project to remote Github:

git push -v origin master
Copy the code

reference

  • Git website
  • Git Quick Start – A guide to Git