GitHub
Version Control with GitHub
Version control with GitHub, or any version control system (VCS) for that matter, offers several significant benefits for individuals and teams involved in software development and other collaborative projects. For this tortorial I will use GitHub.
Setting up a GitHub repository.
Setting up a GitHub repository is a straightforward process. Here are step-by-step instructions on how to create a new GitHub repository:
Sign In to GitHub: If you don't have a GitHub account, you'll need to sign up for one at https://github.com/.
Log In: Log in to your GitHub account if you're not already logged in.
Navigate to Your Dashboard: After logging in, you'll be on your GitHub dashboard. If not, click on your profile picture in the upper right corner and select "Your profile" to go to your personal page.
Create a New Repository:
On your personal page, click the "+ New" button, located in the upper-right corner near your profile picture. Alternatively, you can access this by clicking on the "+" icon in the top navigation bar.
On the "New repository" page, you'll be prompted to fill in some details for your repository.
Set Up Your Repository:
Repository Name: Enter a name for your repository. This should be a unique name and should reflect the purpose or content of your project.
Description: Optionally, you can provide a brief description of your project.
Visibility: Choose whether your repository should be public (visible to everyone) or private (visible only to you and collaborators). Note that private repositories may require a paid GitHub subscription.
Initialize this repository with: You can choose to initialize your repository with a README file, a .gitignore file, and a license. These are optional but can be helpful for getting started with your project.
Template: If you're creating a specific type of project (e.g., a Python package or a Node.js application), you can select a template that provides an initial project structure.
Choose a License (Optional): If you plan to open-source your project, it's a good practice to choose an open-source license that suits your project's needs. GitHub provides several license templates to choose from. If you're not sure which license to use, you can learn more about them at https://choosealicense.com/.
Create Repository: After filling in the required information and customizing your repository settings, click the "Create repository" button. GitHub will create your new repository and take you to its main page.
Your GitHub repository is now set up and ready for use. You can add code, documentation, and other project files to it, and you can also invite collaborators to work with you on the repository by using the "Settings" > "Manage access" tab. Make sure to follow best practices for managing and organizing your code within the repository for a smooth development experience.
Cloning the repository to your local machine.
Cloning a GitHub repository to your local machine using Visual Studio Code (VS Code) is a common and straightforward process. Here are the steps to clone a repository:
Open Visual Studio Code: Launch VS Code by clicking on its icon in your applications menu or by running the code command in your terminal or command prompt.
Clone a Repository:
In VS Code, open the "Source Control" view by clicking on the source control icon in the sidebar. It looks like a square with a branch icon.
In the Source Control view, click on the "Clone Repository" button (it may also be labeled "Clone Repository from GitHub").
If you're not already signed in to your GitHub account in VS Code, you'll be prompted to sign in. Follow the prompts to sign in using your GitHub credentials.
Select a Repository to Clone:
A list of your GitHub repositories will be displayed. You can also search for a repository if you have many.
Click on the repository you want to clone. If it's a private repository, you may need to authenticate with your GitHub credentials again.
Choose a Local Folder:
After selecting the repository, choose the local folder on your computer where you want to clone the repository.
You can use the default suggested folder or click the "..." button to browse for a different location.
Clone the Repository:
Click the "Clone" button to start the cloning process. VS Code will download the repository to your local machine.
Open the Cloned Repository:
After the repository is cloned, VS Code will automatically open it in a new window.
You have now successfully cloned the GitHub repository to your local machine using Visual Studio Code. You can start working with the code, making changes, and using VS Code's integrated Git features to manage your repository.
Remember that you'll need to have Git installed on your local machine and configured with your GitHub credentials to clone private repositories. If you haven't already configured Git, you can do so by following GitHub's guide on Setting up Git.
Committing and pushing the FastAPI application to GitHub directly from VSCode.
Committing and pushing a FastAPI application to GitHub from Visual Studio Code (VS Code) involves using Git, which is integrated into VS Code. Here are the steps to commit and push your FastAPI application to GitHub:
Committing and Pushing Changes:
Open VS Code: Launch Visual Studio Code by clicking on its icon in your applications menu or by running the code command in your terminal or command prompt.
Open Your FastAPI Project: Use the "File" > "Open Folder" option to open your FastAPI project folder in VS Code.
Make Changes to Your Code: Make the necessary code changes or updates to your FastAPI application in VS Code.
Save Your Changes: Save the changes you made to your code by pressing Ctrl+S (Windows/Linux) or Cmd+S (macOS).
Open the Source Control View:
Click on the source control icon in the sidebar. It looks like a square with a branch icon.
In this view, you'll see the list of changes you made to your code.
Stage Your Changes:
In the Source Control view, you'll see a list of your changed files. To stage changes for commit, click the "+" icon next to the files you want to include in the commit.
Alternatively, you can click the "+" icon at the top to stage all changes.
Commit Your Changes:
After staging your changes, enter a meaningful commit message in the text field at the top of the Source Control view. This message should describe the changes you made.
Click the checkmark icon or press Ctrl+Enter (Windows/Linux) or Cmd+Enter (macOS) to commit your changes.
Push Your Changes to GitHub:
After committing your changes, you can push them to your GitHub repository by clicking the "..." icon in the Source Control view.
Choose "Push" from the dropdown menu to push your changes to GitHub. You may need to authenticate with your GitHub credentials if you haven't already.
Monitor the Push Process:
VS Code will display the progress of the push operation in the bottom-right corner of the window. Once it's completed, your changes will be updated on your GitHub repository.
Your FastAPI application changes are now committed and pushed to your GitHub repository from Visual Studio Code. You can verify your changes by visiting your GitHub repository on the GitHub website.
Remember to commit and push your changes regularly to keep your GitHub repository up to date with your local development work.