Title: Intro to Git and GitHub (Version Control)

Intro

This guide will walk you through the essential GitHub basics required to upload your Streamlit project to a GitHub repository, enabling you to deploy your application on the Streamlit Community Cloud.

An Intro to Git and Github
  • ✦ Version control is a big technical topic by itself, encompassing a wide range of concepts, commands, and best practices.
  • ✦ The purpose of this note is to provide a high-level introduction to Git and GitHub, focusing on the essential aspects that will help us get started.
  • ✦ As we become more comfortable with these tools, we should to explore more advanced features and workflows to fully leverage the power of version control in your development process.
  • ✦ There is no lack of resources on Internet on Git and GitHub for us to explore and learn!

What is GitHub?

GitHub is a web-based platform that uses Git, a version control system, to help developers collaborate on projects. It allows you to store your code in repositories, track changes, manage project versions, and collaborate with others seamlessly.

GitHub is a web-based platform that hosts Git repositories. It provides additional features for collaboration and project management, such as:

  • Remote Repositories: Store and share code in the cloud, making it accessible from anywhere.
  • Pull Requests: Propose changes to the codebase, review them, and discuss with team members before merging.
  • Issues and Project Management: Track bugs, feature requests, and manage project tasks.
  • Continuous Integration/Continuous Deployment (CI/CD): Automate testing and deployment processes. Imagine a magical pipeline: every time you save your work, it's automatically tested for errors and if everything looks good, instantly becomes available for users to try or use. That's CI/CD in a nutshell!

For deploying Streamlit applications, GitHub serves as the central repository where your project files reside, which Streamlit Community Cloud can access to run your app.

What is Git?

Git is a distributed version control system that allows us to track changes in our codebase over time. It enables us to:

  • Track Changes: Keep a history of all changes made to the code, making it easy to revert to previous versions if needed.
  • Collaborate: Work seamlessly with other developers by merging changes and resolving conflicts.
  • Branching and Merging: Experiment with new features or fixes in isolated branches without affecting the main codebase, and merge them when ready.

  • In essence, Git is the version control system that powers GitHub.
    • While Git handles the behind-the-scenes tracking of code changes locally on your computer, GitHub provides the user-friendly interface and additional tools that make collaborating and managing projects with Git more accessible.
    • GitHub adds a layer of social coding, enabling features like pull requests, issue tracking, and project management tools.



Setting Up a GitHub Account and GitHub Desktop

GitHib Acount

Before you can use GitHub, you need to create an account.
✦ Steps to Create an Account:

  1. Visit GitHub: Go to GitHub’s website.
  2. Sign Up: 
    1. Click on the "Sign up" button typically located at the top-right corner.
    2. You can use your personal or official email for the registration.
  3. Enter Details: Provide a username, your email address, and a strong password.
  4. Verify Email: GitHub will send a verification email. Click the link in the email to verify your account.
  5. Complete Setup: Follow the on-screen instructions to complete your profile setup.
We will cover the details on how to use GitHub Desktop for the purpose of deploying Streamlit App in the next note.


Download and Install GitHub Desktop

Download GitHub Desktop from here and install the software on your laptop that you are using for this Bootcamp.

There is no need to install git separately since GitHub comes with its own bundled version of git.



Getting Started with Git (GitHub) in VS Code

💪🏼 This is a great tutorial from Official YouTube channel of Visual Studio Code. This 7-min video covers all the key steps to use Git within VC Code, allows you to efficiently manage your code repositories, push your code to the remote repository, and track changes, directly from the code editor.

Since we have installed GitHub Desktop, we can skip the step for installing git. The rest of the video is still applicable.



.gitignore


What is .gitignore?

The .gitignore file is a special file used by Git to determine which files and directories to ignore in a project. When you add files to your repository, Git tracks changes to those files. However, some files should not be tracked—for example, temporary files, sensitive information, or dependencies that can be recreated. The .gitignore file tells Git to exclude these files from version control.

Key Points:

  • Purpose: Prevents specific files or directories from being tracked by Git.
  • Format: A plain text file named .gitignore placed in the root directory of your project.


Why Use .gitignore?

Using a .gitignore file offers several benefits:

  1. Security: 
    • Protect sensitive information like API keys or passwords by excluding them from your repository. (e.g., our .env or secrets.toml files)
  2. Efficiency: 
    • Avoid cluttering your repository with unnecessary files (e.g., temporary files)
  3. Collaboration: 
    • Ensure that all collaborators are not burdened with irrelevant files, maintaining a clean project structure. (e.g., our venv folder)
  4. Deployment: Streamlit Community Cloud and other deployment platforms require a clean repository. Excluding unnecessary files ensures smoother deployments.


How to Create .gitignore?

within VS Code,  create a plain text file named .gitignore placed in the root directory of your project. Add the filenames or directories for the file or folders that you want to exclude from being tracked by git or GitHub into the .gitignore file.

Below are some common entries in the .gitingore for a Python project.

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Virtual environments
venv/
env/
ENV/
.venv/
.env

# Distribution / packaging
build/
dist/
*.egg-info/

# VS Code 
.vscode/ 
# PyCharm 
.idea/


# Streamlit
.streamlit/secrets.toml
It's okay to include entries in the .gitignore file, even if the files do not exist in the current project. This will not cause any errors.



[Extra] Additional Great Videos for VS Code

💡👨🏻‍💻👩🏻‍💻 If you want to collaborate in real-time with your team members in VS Code, this is a great video to get started:


🍽️ Wanting more? Here is a series from GitHub's official YouTube channel designed to help you master the basics of GitHub, whether you're new to coding or looking to enhance your version control skills.