When working on larger programming projects, version control is very important. Git is one popular software that is used for version control and can be leveraged on personal and collaborative work. When working on Python projects in PyCharm, Git can be integrated into the project in a way that doesn’t require use of the command line. This can be interfaced with Pineapple, Champlain’s own project management server, in order to backup and save your project in a versioned way.
Configuring Git with PyCharm
- First, make sure Git is installed on your system. Download it for your system here.
- Create a project in PyCharm or open your existing project that you would like to configure with Git.
- On the top bar of PyCharm, click on VCS > Enable Version Control Integration…
- On the popup, select Git and click OK.
- You should see some new icons in the top right of your PyCharm window. These buttons are for interacting with local Git on your computer.
Basic Git Usage
Git can be very complex to dive into, and is often used in a command line environment. Thankfully, PyCharm builds this functionality into the IDE. It’s still necessary to understand the basic steps of using git as they pertain to PyCharm’s options.
Committing is used when a change is made to a file. This can be useful if you have a piece of code that you’ve just added a feature or changed and you’re at a point where you’d like to save your progress. Later, this progress can be seen in incremental steps for others to review. You must leave a comment every time you commit as a quick summary of the changes that you’ve made since the last commit. In PyCharm, this shows up as a green check button and should be visible from the top right of your editor window:
When you commit, you will be greeted with a popup in PyCharm that will show you the differences between your old and new versions with a prompt for your commit message. This can be useful to track changes yourself and when working on a team.
Clone is used when there is code in a remote repository that you need locally on your system. This can be useful if a team member has added a file to the repository that you now need, or if you are on a new system and need to obtain your data from the repository.
Push is used to send the commits and changes that you have made locally on your system to a remote repository. This is different than forking and pulling in repositories and is best suited to individuals working alone on a project. For smaller solo projects, it can be easier to have one repository from which you clone, commit, and push for both version control and remote storage.
Pulling is best suited to group work or managing larger pieces of code and projects. When a pull is made, changes on one local file are merged into the master file. In collaborative projects, this allows multiple people to work on the same file at different spots. When a pull request is issued, the user’s local copy of the code is pulled back into the master branch. The master branch should always be functional, so pulls should only be made when the code is sound. In larger projects and environments, there is typically a review process prior to the pull request being approved.
Interfacing Git with a Pineapple Repository
- To interface your local Git repositories and versioning with the Pineapple server, you must modify some additional settings.
- Navigate to VCS > Git > Remotes as shown below:
- Now, click the plus icon. Keep the default name of “origin”. For the URL, we will need to create a repository and pull our link from Pineapple.
- In Pineapple, create a new project and repository for your project if you don’t have one already. Navigate to the Repository tab and copy the HTTPS link to it:
- Go back into your window in PyCharm and paste the link into the URL for origin and click OK.
- To copy the changes that you’ve made on your system to Pineapple, you need to push them to the remote server. To do this, click on VCS > Git > Push as shown below:
- Refresh and check your repository in Pineapple. You should see your files that you have pushed from PyCharm.
There are a vast amount of resources online that can help you get comfortable with Git and familiar with more advanced concepts such as branching in collaborative projects. This documentation from Atlassian can be great at getting you further acquainted.