Skip to main content

Command Palette

Search for a command to run...

Using Git for Version Control on PythonAnywhere.

Published
2 min read

Introduction

In this article, I will guide you through the version control using Git on PythonAnywhere. Committing changes: This guide does include several sections like initializing a Git repository, making changes and committing to it for multiple times, and finally pushing the project at GitHub. At the end of this topic, you will be able to identify and explain how to use Git to optimize working with files in your project.

Outline:

  1. Initializing Git

    The first step was to initialize a Git repository in my project folder. This was done in a PythonAnywhere Bash console.

     # Navigate to the project directory
     cd /home/yourusername/projects
    
     # Initialize Git in the folder
     git init
    
     # Verify Git initialization
     ls -a
    

    Initializing Git created a .git folder, indicating that version control was now active in the project directory.

  2. It is very time consuming to make changes to the file and commit 10 times.
    It was after initiating Git that I created a file that is, Project_file. txt and made a change, committed it ten times. This enabled me to take track on every version of my file.

    1. Commands Used:

      Create a new file and make the first commit:Create a new file and make the first commit:

       echo "Initial content" > project_file.txt
       git add project_file.txt
       git commit -m "Initial commit: add project_file.txt"
      
    2. Modify the file and commit changes: For each subsequent change, I followed this process:

       echo "Change 1" >> project_file.txt
       git add project_file.txt
       git commit -m "Commit #1: added Change 1"
      
       # Repeat for all 10 commits:
       echo "Change 2" >> project_file.txt
       git add project_file.txt
       git commit -m "Commit #2: added Change 2"
      
  3. Adding a Remote Repository and Pushing the Code to GitHub

    All commits were then done locally, after which the author linked their local Git repository to a remote repository on GitHub to host the code online.

    1. Add a remote repository: I was able to create a new repository on GitHub and connect it with my local folder with the project:

       git remote add origin https://github.com/yourusername/ACT3.git
      
    2. Push the changes to GitHub: Finally, synchronized all commits in the local repository with the remote repository:

       git push -u origin main