(MACOS Apple system) How to use git (simple version) to quickly get started with Git (IDEA/Terminal)

 1. Use IDEA

(Use IDEA's git plug-in to upload the project to GitHub)

1) Search for "github" in IDEA and click Share

2) GitHub account authentication

 There will be a place below where you can choose to share and then click to jump to the URL to enter the certification.

Later, I discovered that there is an additional leetcode repository on the github account (we uploaded it)

3) Use of git: IDEA upper right corner

2. Use Terminal

 Make sure you have downloaded git:

Verification: Enter the code in the terminal to verify

git

1. Initialize the warehouse

1) Configure local warehouse information

Enter the code as follows:

git config user.name "用户名" --global 
git config user.email "本地仓库的邮箱" --global

(The email address here does not have to be the same as the account on github, it is just a distinction)

2) Initialize the warehouse

Enter the code as follows:

git init

I have already initialized it here. The above information shows that the initialized warehouse is saved in the hidden file '.git'.

(If you want to know how to display hidden files in MACOS system, you can read my previous note and click here to jump .) 

2. Connection of SSH key

1) Create a key 

Enter the code as follows:

ssh-keygen -t rsa(模式,默认是rsa) -C "commit一般写邮箱"

Take my account as an example:

ssh-keygen -t rsa -C "[email protected]"

3) Copy the public key

①First find the location of the public key

There is a pair of generated keys, one is the private key (id_rsa should be kept well by yourself), and the other is the public key (id_rsa.pub).

The private key is saved in id_rsa and the public key is in id_rsa.pub

② Open the file and copy the public key

4) Open github-setting and click to add a new SSH key

 We copy the public key we just copied and click Add to add it (as shown in the picture).

3. Use git

1) Add files to the data staging area

Enter code:

git add 文件路径

2) Check status

Enter code:

git status

3) Submit the information for this push

Enter code:

 git commit -m "描述本次提交的文件" 

4) Push the local warehouse to the github remote warehouse

Enter code:

git push -u origin main  

Here git push -u origin (alias of the remote repository) main (branch name of the repository to be pushed to)

(Sudo is added to the code here because it seems that the file cannot be accessed. Add sudo to force access. You will need to enter a password in the next step) 

5) Set global user information and debug error reporting issues

If the above situation occurs, there may be three reasons:

Let’s explain the first situation:

Based on the answer above, enter the code to verify:

ssh -T [email protected]

The result is as follows:

 What to do if you don’t have an authenticated SSH key?

①Solution 1: Set global information


(Global information is username and email. The information here must be used when registering github), enter the code:

Set username
git config --global user.name alpine9
Set up email
git config --global user.email [email protected]

Check out the information:

git config --global --list  

 Here again enter the code verification:

ssh -T [email protected]

That should do the trick.

②Solution 2: Enter 2 lines of code

Enter code:

ssh-agent -s
ssh-add ~/.ssh/id_rsa

I don’t know what these two lines of code mean. If someone knows, I hope you can enlighten me.

 Enter the code again to verify:

ssh -T [email protected]

Successfully connected to github account.

Push the local warehouse to the remote warehouse (github) again and enter the code:

sudo git push -u origin main

 

 Submission successful!

Here is the operation to remove the current warehouse and convert it to another warehouse:

 

references

Reference for this article: Nanny-level tutorial to teach you to use Git to push your project to Github_git push to github_Qianfan Guojin's Blog-CSDN Blog

Guess you like

Origin blog.csdn.net/weixin_67225910/article/details/132159252