Git Notes

Git Notes

[[144417]]

Preface

Git is indeed a very good version management system. I won't talk about its advantages here for now, and there are many related materials on the Internet.
Write these down for easy reference and understanding later.

  • Some good Git learning resources
  • Git branch management strategy
  • Pro Git books
  • Git interactive learning
  • A quick guide to GitHub for designers
  • Go to GitHub

The following are some simple notes for future reference. Of course, if you want to systematically learn the principles of Git, you can refer to the learning resources listed above.

About Installation

Please move to Git installation, of course it is best to install it under Linux.

Create a repository

  • Use the git init command to turn the current directory you are in into a repository that can be managed by Git; you can see the .git directory in the current directory
  • Generally, when you want to add a newly written file to the repository management, use the command git add youfile
  • Commit the files added to the repository above to the repository using the command git commit -m "your annotation information"; Note: Remember to fill in the comment you modified after the -m parameter so that other developers can read it.
  • The git status command can be used to view the current status of the repository at any time, such as which files have been changed, which have been submitted, and which files are not tracked.

Operating remote warehouse

Generally, you can build a Git server that you run yourself. If you don't have the conditions, use the Github website, a website that provides warehouse hosting services. Here you can understand Github as a Git server, but it does not provide private warehouses for free.
So, if your project is not public, you either have to pay some fees or build a Git server yourself.
No more words

  • First register an account on it, my account
  • Then you click "Create a new repo" to create a new repository (my new repository is COS-IIAPP) and set it up according to the default settings.
  • Link your local repository. Note: It is best to name the local repository the same as the repository you created on Github. Run the command in the directory where the local repository is located:

    1. $ git remote add origin git @github .com:yourcount/hello-world.git

    The origin is the remote library

  • Push all the contents of the local library to the remote library

    1. $ git push -u origin master

    Of course, if you have created other branches locally (don’t know what a branch is? Don’t worry, why don’t you read the branch I will introduce later), you can also push them. Just change master to the name of the branch you want to push.
    You can also clone from a remote repository to a local repository, with the same effect.
    OK, congratulations, you have reached this step, now you can check if your GitHub project is the same as your local project! Damn! No? ? Okay, forget about the next step.

    Create SSH Key

    By the way, you need to create an SSH Key before this, because the transmission between your local Git repository and GitHub repository is encrypted via SSH.

    1. $ ssh-keygen -t rsa -C "youremali.com"

Parallel development

The power of Git lies in its collaborative development.
Now suppose your other members develop a project together in the dev branch.

  • He used the git clone [email protected]:guxiaole/COS-IIAPP.git command to clone it to his local repository
  • He wants to create the dev branch of the remote origin locally, use this command git checkout -b dev origin/dev;
  • He is very good and quickly developed a great idea on the dev branch. After pushing it to the remote library git push origin dev, he happily went to watch Mr. Aoi's movie.

At this time, you work overtime to modify it on dev, and when you finally get it done, you try to push it to the remote library, and then you will get an error message. . Damn, that guy is faster than me!
Reason: Push failed because the remote branch is newer than your local branch.
Solution:

  • First try to merge with git pull; Note: If git pull prompts "no tracking information", it means that the link between the local branch and the remote branch has not been created. Use the command git branch --set-upstream dev origin/dev
  • If there are conflicts in the merge, resolve the conflicts and commit them locally;
  • After there is no conflict or the conflict is resolved, push it with git push origin dev

Branch Operation

  • The default initial branch is master. Generally, the more stable project version is on this branch. Once other mature functional branches are developed and tested to be stable, they will be merged with this branch.

  • Now you need to develop a new feature with other members. Generally, you create a new branch and happily make changes and commits on it. Of course, at this time, it has not been merged with the main branch.

  • At this time, someone suddenly reports that a bug in the stable version master you released needs to be fixed. At this time, stop the dev branch at hand and switch to the master branch.

  • Create a new bugfix branch and modify the commit

  • Bug fixed, merged into main branch

  • Go back to the dev branch and continue working. Find that the new function of dev is completed and merge the master branch

  • Oh, I forgot that the bugfix branch can be deleted at this time.

  • In addition, when the work at hand is not completed, first git stash the work site, then fix the bug, and then git stash pop to return to the work site

summary

That's about it for the most commonly used Git commands. I'll keep updating them as I learn more. Of course, if you want to thoroughly understand the principles of git, you should read related books systematically.

<<:  Apple may want to change its tactics, such as developing Android apps

>>:  The transition from developer to manager

Recommend

Douyin Teacher Li's Mathematical Thinking Course (Grades 1-3)

Douyin Teacher Li's Mathematical Thinking Cou...

LG's first 2K screen mobile phone preview

Yesterday, LG's first 2K screen mobile phone i...

Samsung's foldable phone is amazing, but it's still not perfect

Strip away the outer shell of technology and para...

ZCOOL Master Hou Shuai's E-commerce Design All-Round Class

ZCOOL Master Hou Shuai's E-commerce Design Al...

Data analysis for event promotion, learn it now

PSM is not suitable for all marketing scenarios. ...

ROG's ultimate belief! How powerful is the overclocking brother from ASUS?

The ultimate flagship returns ASUS Republic of Ga...

Smart bra tops the list? Check out these useful smart products

Since the concept of smart hardware became popular...

Uncovering the magic number behind user growth [5]

"5 times" is a magical number. Users wh...

How to position a short video account?

Nowadays, many people regard shooting short video...

Learn 3 tricks to easily promote your product

Product promotion does not necessarily require &q...

How to increase online user growth during the epidemic

In special times, shifting from offline to online...