Upload your local project to the github repository in Pycharm - suitable for "novices" with certain experience

Tip:
This is my first time writing a blog. It is used to record the problems and solutions I encountered and for your reference.
Sorry for the rough content.


Preface

This article mainly records my ownHow to synchronize projects from your local computer to your own github repository in pycharm, friends in need can refer to it.
Tools and environments used: windows11, pycahrm2021.2, git2.33.0, github.
The tools here are not introduced one by one. Friends who need it can go online to learn about it by themselves. This article assumes that you have a certain understanding of pycharm, github, and git, and hope to use github's version control function directly under pycharm.


1. Prepare necessary tools

  • Install plug-ins in pycharm: github, git
    Download in pycharm
  • Download and install git on your computer. Follow the download and installation steps from Baidu.
    Insert image description here

2. Operation steps

1. Configure git and github in pycharm

First, open your own local project in pycharm. If it has not been configured before, the main interface should be like this. I will use a brand new project as an example. You can see that there is a VCS in the top bar. Insert image description hereThen open Settings and click Version Control.
Insert image description here

Then create a git repository. There are two methods:

  • One is to add the VCS directory directly in version control, click the ➕ sign on the right, select the project root path, select git for VCS, and then click OK.

Insert image description here

  • The other is to click VCS on the top bar of the main interface, then click Create git repository, then select the project root path and click Confirm. At this time, you can see that the VCS in the top column has changed to git.

Insert image description here
Then configure git and github, double-click version control, select git in the list that opens, then configure the installation path of git, click Test to display the version and it will be ok. To configure github, you mainly need to log in to your github account.
Insert image description here
Insert image description here

2. Get ssh key (key)

To successfully upload your project to GitHub, you must configure an SSH key for your GitHub account.
Configuration method:

  1. In your own project folder, right-click the mouse and select Git Bash here to pop up the Git command box
  2. Enter the command ssh-keygen in the command box, and then click enter all the way. Fill in y when you encounter y. At this time, an id_rsa.pub and an id_rsa file will be generated in the .ssh folder under your user name in the system disk. Use Open id_rsa.pub in Notepad, copy all the characters, then log in to your account in github, select SSH and GPG Key in the account settings, create a new SSH Key, and paste all the characters you just copied here.

Insert image description here
Insert image description here

3. Connect the local project to the github repository

There are two options here:
1. You can first create a warehouse in github, then click git in pycharm, select Manage Remote, and then add the newly created warehouse address of github to it, and the warehouse will be connected to the local area. 2.
Insert image description here
Insert image description here
Second One solution is to create a GitHub repository directly in pycharm. First click on git, then click on github, then click on share the project on github, then click in to set the name of your own warehouse, select whether it is private, and you can also add a description. Click Share, and the local project will be connected to the GitHub repository. You can go to github to view the created warehouse.
Insert image description here

4. Synchronize local projects to github

1. Here I first created a warehouse named Test, which has been connected to my local project. You can see that there is nothing in the warehouse at this time.
Insert image description here
Insert image description here
2. Then I started submitting the code for the first time. Click on git in the top bar, then click Submit. Submitting means to record a series of modifications to the project. At this time, it has not been synchronized to the remote github warehouse. I just tell the system in advance that I will synchronize these things. For a project created for the first time, all project files will be submitted by default when submitted for the first time. You can choose to uncheck the files that are not yet submitted. For example, I will not submit the .idea folder by default here, and then fill in the submission information, which is a description of this submission. You can describe the modification information of this submission, and then click the submit button below.
Insert image description here
3. Then start pushing, that is, synchronizing the project files to the GitHub repository. Click git, then click push, you can see the submitted information, then click this information, click push below, wait for a while, the push is successful.
Insert image description here
Insert image description here
At this time, you can go to the GitHub repository to view the synchronized project information.
Insert image description here
4. If you want to submit and push the project to GitHub again, just repeat the above operations, submit first, and then push. As shown in the picture:
Insert image description here
Insert image description here
Insert image description here

Remark

In Git, "push", "commit" and "pull" are three very important concepts.

  1. Push: refers to submitting local code to a remote repository, that is, synchronizing local code to GitHub or other Git servers. The Git push command pushes local code to a remote repository so that others can see and collaborate on development.
    git push origin master
    Explanation: Push the local master branch to the remote warehouse named origin.

  2. Commit: refers to saving local modifications to the Git local warehouse and recording the operation log of each submission for future viewing, rollback and other operations. The Git commit command organizes the files you have modified locally into one submission and records the corresponding submission information.
    git commit -m "Update README.md"
    Explanation: Commit the modification to the README.md file and add a line of commit information.

  3. Pull: refers to synchronizing the code of the remote warehouse to the local Git warehouse. The Git pull command downloads the latest code from the remote repository to your local so that you can collaborate or test with the latest code.
    git pull origin master
    Explanation: Extract the latest master branch code from the remote repository named origin, and then merge it into the current branch of the local repository.

To sum up: In Git, the "push" operation is to synchronize the commits in the local warehouse to the remote warehouse (such as GitHub); while the "pull" operation is to synchronize the modifications in the remote warehouse to the local warehouse.

Specifically, when we use Git to push a local branch, Git will upload our commits in the local warehouse to the remote warehouse so that others can see and collaborate on development. When we use Git to extract operations, Git will automatically download the latest commits from the remote repository to our local repository so that we can get the latest code.

It should be noted that before performing a push or pull operation, we need to ensure that the code in the local warehouse and the remote warehouse are in a consistent state. Therefore, before performing a push operation, it is recommended to perform a pull operation to ensure that we have the latest code and resolve any conflicts before pushing.

Summarize

The above are the steps for uploading your local project to the github warehouse in Pycharm. There may be many problems, and I would like to ask many seniors for their advice.
Another thing to note is that I previously created a warehouse in pycharm, and then it was always rejected when I pushed it synchronously. At this time, I configured a separate ssh key for my warehouse to push, but now I don’t need to My warehouse can also push the key if it is configured separately. My personal guess is that I updated the key of my GitHub account, so there is no need to configure the key separately for the warehouse. If anyone encounters similar problems, you can Use git to generate a new key locally, and then update the key of the GitHub account or add a new key to the repository. The function of the key is nothing more than to establish a connection with the github repository, so if you encounter such problems, you can do this Try several ways.
In addition to submitting and pushing your own projects in pycharm, you can actually submit and push projects directly in the git command line. I won’t go into details here. Maybe I will write an article on submitting and pushing projects in the git command line in the future. blog. Hope it could help everyone.

Finally, this article only represents my understanding and opinion on this at this moment. There may be some mistakes. If there is something wrong in the article or the description is unclear, please give me some pointers.

postscript

Every time I encountered a problem in the past, after finally solving it, the most I could do was find a text to record it, or just let it go. I have never thought about recording it in the form of blogging. I tried it for the first time today, and I am still very excited. I hope that all the friends who are exploring like me can work hard and learn together ~ I will continue to update in the future.

Guess you like

Origin blog.csdn.net/qq_45930085/article/details/130052717