Using Git for Version Control on PythonAnywhere.
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:
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 -aInitializing Git created a
.gitfolder, indicating that version control was now active in the project directory.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.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"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"
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.
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.gitPush the changes to GitHub: Finally, synchronized all commits in the local repository with the remote repository:
git push -u origin main