Add, commit, and push

Again, we will try to perform all the tasks in the version control pipeline we have discussed in the previous section using PyCharm. Here, we will see how we can add files to Git, commit them, and finally, push them on the GitHub repository created at the beginning for this section.

To add a specific file to Git, simply select it within the Version Control panel, right-click on the file, and select Git | Add, as illustrated, where I was adding the main.py file to Git:

Adding files to Git in PyCharm

Alternatively, you can also go to VCS | Git | Add in the menu bar, or use the corresponding keyboard shortcut. After the add is performed, you should be able to see that the file has been moved to the Default Changelist section, and is now highlighted in green (again, indicating that it is registered by Git and has not been committed).

Note that you can also select multiple files at the same time in the Version Control panel and add them to Git simultaneously. To add all the unversioned files to Git, you can also select the Unversioned Files section itself and evoke the add action. For now, just add the main.py file to Git.

Furthermore, to remove a file from Git, you can select that file within the Default Changelist, right-click, and choose Revert. Doing this will have Git unregister the file, and move it back to the Unversioned Files section. Again, we only want main.py committed in our current example, so go ahead and revert any file that you accidentally committed using this method.

The process of committing files is fairly similar to what we just saw with adding. To commit the files highlighted in green in the Default Changelist section (which we only have the main.py file for now), right-click on them and select Commit, or use the corresponding keyboard shortcut.

The following pop-up window will appear, showing information regarding the commit that we are attempting:

The commit window in PyCharm

In the middle-left section of the window, you can enter a commit message indicating the purpose of the commit, which will be displayed on GitHub. Furthermore, in the bottom section, you can see the differences between the file(s) you are committing and their previous versions; the default comparison is displayed side by side (which you can further customize).

When you have entered a commit message, you can finalize the process by clicking the Commit button. After a file has been committed, it will disappear from the Default Changelist section.

Additionally, you can also evoke the Commit button, conveniently placed in the top-right corner of the project window by default, when files you'd like to commit are selected:

Version Control's Commit button in PyCharm

Finally, the last step is to push the committed portion of the project (which consists of the main.py file only for now) to GitHub. Go to VCS | Git | Push to perform this task and another pop-up window will appear.

If you are pushing to GitHub for the first time in this project (which we are if you are following the example), there will be a Define remote link in the main section of the window, which we can use to establish the connection between our local project and a GitHub repository:

Adding remotes in PyCharm

Click on the link and input the URL to the GitHub repository that you created at the beginning of this section. After this, you can push the local project you have to this repository on the cloud. You can go to that repository on GitHub to see the pushed main.py file after this process is complete.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.180.76