Idea configure and use git

Use of Git Gui

Insert picture description here

Ssh key introduction and use

Ssh key introduction
What I understand is that each computer will generate an ssh key, and then have a remote account, but I may have many computers,
including home computers and company computers, we can use any one Work on the computer, but if you want each computer to keep communicating with the remote repository at all times,
you need to add the ssh key of each computer to the remote account. After adding to the remote repository, the remote repository will be added Computer communicates without communicating with other computers

Recommendation: All Git operations are carried out through ssh key, because it is simple

Ssh key configuration

The operation is divided into local computer configuration and github website configuration.
Step 1: Local computer configuration.
Right-click on the blank space and select Git Bash Here to open the relevant command window
. 1. Configure the user name and email (if configured, skip it)
git config --global user .name "username"
git config --global user.email "email"
will create a .gitconfig file under C:\Users\Administrator with the content
[user]
name = xxx
email = [email protected]

 注1:username和email即github的登陆帐号和注册邮箱
 注2:git config命令的–global参数,用了这个参数,表示你这台机器上所有的Git仓库都会使用这个配置

2. Check if you have generated ssh
cd ~/.ssh
ls before

 注1:当cd ~/.ssh命令执行后窗口返回“no such file or directory”的时候,表示我们的电脑并没有ssh key,所以需要我们创建ssh key
 注2:~表示当前用户的目录,比如我的是:C:\Users\Administrator
 注3:ls命令执行后,如果本地有ssh秘钥的话会有id_rsa.pub,config,known_hosts等文件

3. Generate (or delete) the secret key
ssh-keygen -t rsa -C "[email protected]"//The mailbox here needs to be replaced with the mailbox when you registered and
then press 3 enters .

 注1:如果本地有ssh,执行以上命令会出现正面的提示,这里选择y,表示覆盖本地的ssh key,其实也就是ssh秘钥删除的意思
 注2:为什么要删除秘钥,创建SSH的时候设置过密码,那就很有可能git操作时出现忘记密码的尴尬情况,
      不要想着怎么重新修改密码了,选择重新创建一个ssh秘钥  
 注3:创建ssh key不要输入密码了,不然操作起来太累~~~~~~~ 

4. After the execution of the command is completed, by default, files with the following two names will be generated under C:\Users\Administrator.ssh in the window:
C:\Users\Administrator.ssh
id_rsa (private key, cannot be leaked)
id_rsa.pub( Public key)
known_hosts (don't care)

Step 2: Remote github repository configuration
1. Log in to your gitbub, click the inverted small triangle in the upper right corner. Select settings
2. Select SSH and GPG keys
3. Click New SSH key on the right
4. Feel free to fill in a title, then paste the id_rsa.pub text you just copied in the key, click Add key, and you're done.
5. Sometimes the github official website will You need to enter the login password to add the ssh key. Just enter the password

The third step can be omitted. If you use the ssh protocol when you get the Git repository, there is no need to modify it

Step 3: Modify your local ssh remote url. Instead of https protocol, use git protocol instead.
1.git remote -v View your current remote url
git remote -v

 ## 如何显示如下内容,则表示Git仓库是使用https协议进行访问的。
 origin  https://github.com/xieminglu02/library_pub.git (fetch)
 origin  https://github.com/xieminglu02/library_pub.git (push)

2. Use a browser to log in to github and find the corresponding url of the warehouse ssh protocol. Similar to the following:
[email protected]/library_pub.git

3. Use git remote set-url to adjust your url.
git remote set-url origin [email protected]:xieminglu02/library_pub.git

4. Finally check it with git remote -v. Agreement has changed

Insert picture description here
Insert picture description here
Step 4: Test the SSH connection
1. Enter the test command
ssh -T [email protected].
If the following content is displayed, the ssh key has been added successfully:
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.

Summary: The difference between https and SSH:
1. The former can clone projects on github at will, regardless of who owns it; while the latter means that you must be the owner or administrator of the project you want to clone, and you need to add an SSH key first, Otherwise, it cannot be cloned.
2. The https url needs to verify the user name and password when pushing; and when SSH is pushing, there is no need to enter the user name; if the password is set when the SSH key is configured, the password needs to be entered, otherwise it is directly No password is required.
3. Git protocol push remote warehouse does not need to fill in the github account password, the operation is more convenient.
Insert picture description here
If the public key of ssh key is not configured on the official website of github
Insert picture description here

Idea configuration use and use git

Configure Git in idea
1. Set the installation path of git.exe and
click the menu "File->Settings->Version Control->Git", and set the value of Path to Git executable to: D:\tools\Git\bin\git.exe ,

 注1:请将上述路径“D:\tools\Git\bin\git.exe”改为自己git的安装目录
 注2:点击右边的“test”按钮,应该显示成功消息及git的版本信息

2. Set up a Github account
Click on the menu "Settings->Version Control->Github"
to choose one of the following two methods

 注1:认证方式选择密码,即Auth Type:“Password”,然后输入帐号/密码,再测试是否连接成功
 注2:认证方式选择令牌
	在这个网址:https://github.com/settings/tokens/new	生成token令牌

Insert picture description here
Use Git in the idea
1. Create a local warehouse
VCS–>Import into Version Control–>Create Git Repository...
Note 1: Generally, the directory where the current project is located is selected

2. Upload the project to the local warehouse, right-click the project and select Git–>add. At this time, the project file turns green. At this time, the file is only in the temporary storage area and does not actually enter the repository (local)

3. Right-click the project Git–> Commit Directory, enter Commit Message in the pop-up window, and click commit. At this time, the project file actually enters the repository (local) from the temporary storage area, and the project file becomes white.
Note 1: In the pop-up window Enter Commit Message, or click commit and push, it will be submitted to the local library and code hosting website at the same time

4. Upload the project to GitHub, VCS–>Import into Version Control–>Share Project on GitHub, enter the warehouse name and description in the pop-up box, and click Share to upload.

Create a local warehouse.
Insert picture description here
Clone the remote warehouse to the local and become a local warehouse.
Insert picture description here
Insert picture description here
Add the newly created project to the local warehouse cache
Insert picture description here
. Really submit the newly-added/changed files to
Insert picture description here
the local warehouse. Synchronize the local warehouse to the remote warehouse. Establish and then associate, which is different from the way of command)
Insert picture description here

Conflict resolution in Idea

Insert picture description here

Branches are used in super large projects, and you need to learn more when you have time;
create branch command: git branch branch name
view all branch commands: git branch
switch branch command: git checkout branch name
merge branch to master branch command:
first Switch to the master branch, git checkout master, and then git merge the branch name. The branch to be created will be merged into master.
Delete branch command: git branch -d branch name

Guess you like

Origin blog.csdn.net/xieminglu/article/details/102966806