“This is the 9th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

Hi, family, I’m bug bug, here I go again. Let’s talk about something today. OK, let’s continue with the Ubuntu series. Listen and learn! Good cut?

A: Environmental description

Environment: Ubuntu20.04

2: preface

Ubuntu, as a development environment, also needs to do code version management, so the use of Git will not be less, so, based on Ubuntu system, how to set up and use Git?

Here, for xiaobai series of teaching, Bug bug has opened a special column, interested friends can pay attention to “Ubuntu Zero Basic Teaching”, Bug bug do so much just for one thing is to teach you, teaching will not charge tuition!

For those who are helpful to you, please don’t forget to give a thumbs-up to bug bacteria. Your encouragement is the biggest support for me! So then, business as usual! The bugs are going to start class

directory

#git installation

2, #git configuration

3. # Git with Gitlab

4. # Git submission process

#git git

#git installation

Use the command to install it

sudo apt-get install git
Copy the code

1.1 Checking the Git Version

git --version
Copy the code

2, #git configuration

Git config --global user.name "XXX" git config --global user.emailCopy the code

// After the configuration is complete, you need to create a public key for authentication. Because Git uses SSH to access the repository, you need to create a local authentication file.

2.1. Run a command to create a public key. On Linux/macOS, ssh-keygen is provided with the SSH software package.

Execute this command, the email address is optional, generally best to the company email, this has no fixed requirements, depending on your mood; And then you just hit enter three times

Ssh-keygen -c 'Your email address' -t rsaCopy the code

Ps: There is no space between SSH and -keygen, and the corresponding key file will be created in user directory ~/. SSH /.

2.2. Note: If an error message is displayed when you run the preceding command: -bash ssh-genkey: the command is not found

Solutions:

1. Open the configuration file:

vi /etc/ssh/sshd_config
Copy the code

2, Find the following, remove the comment “#”;

Next by the way to the big guy popular science, execute the command generated three files are what to use;

Popular science:

This command generates a.ssh folder containing the following three files:

  • Files are named id_RSA or ID_dsa, one of which has a. Pub suffix that is your public key;
  • The other (XXX) is the corresponding private key;
  • In addition to generating these two files, there is a file called known_hosts; SSH /known_hosts ~/. SSH /known_hosts this file records the public key of each computer accessed by SSH. The next time you access the same computer, OpenSSH checks the public key. If the public key is different, OpenSSH will warn you against attacks like DNS Hijack.

2.2 After the SSH public key is created, you can view that the public and private SSH keys are saved to the /root/. SSH directory. If not clear, you can see the above generated. SSH information print, some print out the save path; As above, I circled; Mine is saved directly to /root; Generally, it is saved to the user directory.

Run the following command to enter the. SSH folder:

cd /root/.ssh
Copy the code

2.3. Run the id_rsa.pub command to open the id_rsa.pub file

gedit id_rsa.pub
Copy the code

2.4. Copy everything. As they were circled by me;

2.5, then open gitLab, follow the following process step by step to open, and then paste your copied ID_RSA. pub public key into the key;

2.6. Now you can upload and download the project code using git command.

Git command training is next, are you ready?

3. # Git with Gitlab

3.1 clone code from GitLab to Ubuntu, find the project code you need to download from GitLab, and then click Clone to copy the SSH address;

3.2 Run the following command to download the code

Git clone + SSHCopy the code

4. # Git submission process

4.1. Check to see if you have modified the file again since your last submission.

git status 
Copy the code

4.2. Add all files in the project to the repository. If you want to add a specific file, add. Replace it with the corresponding file name.

git add .
Copy the code

4.3 For the comments submitted this time, the characters in the double quotation marks are customized.

git commit -m "first commit" 
Copy the code

4.4. Get code remotely and merge local versions

git pull
Copy the code

4.5. Upload local branch versions to remote and merge them

git push
Copy the code

This is the general procedure for your submitted code;

#git git

Here are some git commands that are often used in addition to code submission:

#1 Check git logs

git log
Copy the code

#2 Force the version commit; Note: After mandatory submission, submission versions after the current version will be overwritten!

git push -f 
Copy the code

#3 Check the current version of the branch

git rev-parse HEAD
Copy the code

#4 Fall back to a version of the branch

Git reset - hard + target version number / / eg: git reset - hard a53b892a32b16a93850c121db0f08967143e2707Copy the code

#5 Check the tag

 git tag
Copy the code

List all Git Settings

git config --list
Copy the code

#7 Check the remote warehouse address

git remote -v
Copy the code

#8 Pull all branches of the remote end

git branch -a
Copy the code

#9 specifies that a file modification is discarded

Git Checkout -- [file path]Copy the code

#10 Discard all modification files; Note: this command does not delete the newly created file, because the newly created file has not been added to the git management system, so it is unknown to Git, you can manually delete it.

git checkout . 
Copy the code

In summary, it is the dry goods brought by bug bacteria this period, if not enough to eat, the bug bacteria think again ~~

Three, hot article recommendation:

  1. How to install jdk1.8 and environment variable configuration on Ubuntu20.04
  2. How to install IDEA and IDEA stomp guide on Ubuntu20.04
  3. How to install maven and environment variable configuration on Ubuntu20.04

. .

For more articles on Ubuntu, check out Bug Bug’s Ubuntu Zero-based Teaching column, which will continue to be updated. Teach you how to understand Ubuntu! I use my hands to make your dreams come true.

If you think this article is helpful to you, please don’t forget to click on the bottom left corner of the article to light it up!! If I were you, don’t hesitate to go straight to my favorites to eat ashes! No matter later use not on, first eat ash again, ha ha ha ha ha ha ha belch ~~

If this article has been helpful, please put your thumb in the bottom left corner of the article. (# ^. ^ #);

If you like the articles shared by Bug bug, please send bug bug a note! The danjun ‘ᴗ, you guys will have a cameo appearance with you.

If you have any questions about this article, please leave a comment below or join the group [Group number: 708072830].

In view of limited personal experience, all views and technical research points, if you have any objection, please directly reply to participate in the discussion (no offensive comments, thank you);

Copyright notice: This article is the blogger’s original article, reprint please attach the original source link and this article statement, all rights reserved, piracy will investigate! (* ^ del ^ *).