====== GitHub ====== What is GitHub, and Why Do We Need It? ======================================= **GitHub** is a web-based platform that uses **Git**, a version control system, to help developers manage and store their code. It provides a collaborative environment where multiple people can work on a single project, track changes, and maintain a history of modifications. Why We Need GitHub ------------------ 1. **Version Control**: GitHub allows you to :hl:`keep a record of all changes` made to your code over time. This is crucial for software development as it helps in maintaining a history, rolling back to previous versions if something goes wrong, and understanding the evolution of the code. 2. **Collaboration**: :hl:`It enables multiple developers to work on the same project simultaneously`. They can create branches, make changes, and merge their work back into the main project, all while keeping track of who did what and when. 3. **Backup and Storage**: GitHub serves as a remote repository where your code is securely stored in the cloud. This acts as a backup and ensures that your code is not lost if your local machine fails. 4. **Open Source Community**: GitHub hosts millions of open-source projects. It allows developers to contribute to existing projects, learn from others, and even use code libraries shared by others. 5. **Continuous Integration and Deployment (CI/CD)**: GitHub integrates with various CI/CD tools that :hl:`automatically test and deploy your code` whenever changes are made. This helps in maintaining code quality and speeds up the deployment process. 6. **Issue Tracking and Project Management**: GitHub provides tools for managing issues, feature requests, and bug tracking, which helps in maintaining a clear roadmap and organization of development tasks. 7. **Documentation and Code Review**: It supports :hl:`markdown files for documentation` and has built-in tools for code review, which improves code quality through peer reviews and discussions. 8. **Security and Compliance**: GitHub offers security features like vulnerability scanning, secret scanning, and dependency management to help maintain the security and compliance of your codebase. Overall, GitHub is a versatile tool that facilitates efficient software development, collaboration, and project management, making it an :hl:`essential part of modern software development workflows`. How to Create a GitHub Account ============================== Creating a GitHub account is straightforward. Follow these steps to set up your GitHub account: 1. **Go to GitHub's Website**: Open your web browser and navigate to the `GitHub homepage `_. 2. **Sign Up**: Click on the "Sign up" button, usually located in the upper-right corner of the page. 3. **Enter Your Information**: - **Email Address**: Enter a :hl:`personal email address` (e.g., Gmail account) that you have access to. Please **DO NOT** use GT email address, and **DO NOT** use GitHub Enterprise, because it is known that within one month of your graduation, all your data there will be purged. - **Password**: Choose a strong password (GitHub will provide strength feedback as you type). - **Username**: Choose a unique username for your GitHub account. This will be your public identifier, so pick something professional or that represents you well. - **Verify your Account**: You might need to solve a puzzle to prove that you're not a bot. 4. **Choose a Plan**: GitHub offers both free and paid plans. For most users, and in our case, the :hl:`Free plan is sufficient`. It includes :hl:`unlimited public and private` repositories. 5. **Complete the CAPTCHA**: GitHub might ask you to complete a CAPTCHA to verify you are not a bot. 6. **Verify Your Email Address**: GitHub will send a verification email to the address you provided. Check your email inbox, open the email from GitHub, and click on the verification link. 7. **Set Up Your Profile**: Once your email is verified, you can set up your profile by adding a profile picture, bio, and any other details you’d like to share. 8. **Explore GitHub**: After setting up your profile, you can start creating repositories, forking other projects, contributing to open-source projects, and more. Congratulations! You now have a GitHub account and can start using it to host code repositories, collaborate on projects, and explore other developers' work. How to Create a New Repository, Set it as Private, and Invite a Collaborator ============================================================================ Follow these steps to create a new repository on GitHub, set it as private, and invite Chen (:hl:`cchen5891@gmail.com`) as a collaborator: 1. **Log in to GitHub**: Open your web browser, go to `GitHub `_, and log in to your account. 2. **Create a New Repository**: - Click on the "+" icon in the upper-right corner of the page. - Select "New repository" from the dropdown menu. 3. **Fill in Repository Details**: - **Repository Name**: Enter a unique name for your repository, for example ``my-beautiful-project``. - **Description** (optional): Add a short description of your repository. - **Repository Visibility**: Select ``Private`` to make the repository private. Note that if public is selected, anyone can see your code, and that's not what we want from data security perspective. 4. **Initialize the Repository** (optional): - Check the box to **Add a README file** if you want to initialize your repository with a README. - You can also choose to add a `.gitignore` file and select a license, if desired. 5. **Create Repository**: - Click the **Create repository** button to create your new private repository. 6. **Invite Chen (cchen5891@gmail.com) as a Collaborator**: - Go to the **Settings** tab of your newly created repository. - In the sidebar, select **Collaborators and teams**. - Under "Collaborators", enter **Chen's GitHub username or email address**: :hl:`cchen5891@gmail.com`. - Click **Add collaborator**. - GitHub will send an invitation to Chen. Once Chen accepts the invitation, they will have access to your repository. You can also set permissions for the collaborator if needed. You have now created a new private repository and invited Chen as a collaborator! How to Upload a Folder to GitHub via the Web Interface ====================================================== While GitHub's web interface does not support direct folder uploads, you can upload files from a folder by following these steps: .. note:: This method of uploading files from a folder to GitHub is **NOT** recommended. But if this is the first time you use Git, and you have only a couple of files, it might not be a bad idea for you. For more complex or frequent uploads, it is advisable to use Git via the command line or a Git client, as described in the following section. 1. **Log in to GitHub**: Go to `GitHub `_ and log in to your account. 2. **Navigate to Your Repository**: Go to the repository where you want to upload your files. If you don't have a repository yet, create a new one by clicking on the "+" icon in the upper-right corner and selecting "New repository". 3. **Upload Files**: - On the main page of your repository, click the **Add file** dropdown button. - Select **Upload files** from the dropdown menu. 4. **Drag and Drop Files**: - Open the folder on your computer that contains the files you want to upload. - Drag and drop the files from your computer's folder into the upload area on the GitHub web page. - Alternatively, click on **choose your files** and select multiple files from your computer using the file picker. .. note:: You can select multiple files by holding down the **Ctrl** (or **Cmd** on Mac) key while clicking files. 5. **Add a Commit Message**: - After uploading the files, you will see them listed on the GitHub page. - Add a descriptive commit message in the **Commit changes** box, explaining what the uploaded files are or why you're uploading them. 6. **Commit the Changes**: - Choose whether you want to commit directly to the `main` branch or create a new branch for the changes. - Click the **Commit changes** button to upload the files to your repository. 7. **Repeat for Additional Files or Folders**: - If you have additional folders, repeat the process by navigating into the appropriate folder in your repository on GitHub and uploading files as needed. **Important Note**: If you need to upload an entire folder or maintain folder structure, consider compressing the folder into a `.zip` file, uploading the `.zip` file, and then unzipping it using a local copy or command line tools after cloning the repository. :hl:`For frequent or more complex uploads, it's recommended to use Git via the command line.` Congratulations! You have successfully uploaded files from a folder to a GitHub repository using the web interface. How to Set Up a Local Repository and Push to a Remote Server ============================================================ To set up a Git repository on your local computer and push it to a remote server, follow these steps: 1. **Install Git**: Ensure that Git is installed on your local machine. You can download it from `Git's official website `_ if it's not already installed. 2. **Create a New Local Repository**: Open your terminal or command prompt and navigate to the directory where you want to create your local repository. Then run the following commands: .. code-block:: bash # Navigate to your desired directory cd /path/to/your/directory # Create a new directory for your repository mkdir my-repo cd my-repo # Initialize a new Git repository git init 3. **Add Files to the Repository**: Add the files you want to include in your repository: .. code-block:: bash # Add files to the staging area git add . # Commit the changes git commit -m "Initial commit" 4. **Create a Remote Repository on GitHub**: - Log in to your GitHub account. - Click on the "+" icon in the upper-right corner and select "New repository". - Enter a name for your repository and set the visibility (public or private). - Do not initialize the repository with a README, .gitignore, or license, as this will complicate the first push. - Click **Create repository**. 5. **Link the Local Repository to the Remote Repository**: After creating the remote repository, GitHub will provide a URL for the remote repository. Run the following command in your terminal: .. code-block:: bash # Replace with the actual URL provided by GitHub git remote add origin 6. **Push Local Repository to Remote Repository**: Push your local repository to the remote repository on GitHub: .. code-block:: bash # Push the changes to the master/main branch git push -u origin master Note: If you are using GitHub's newer default naming conventions, replace `master` with `main` if necessary. 7. **Verify the Push**: Log in to your GitHub account and navigate to your repository. You should see the files you pushed listed in the repository. Congratulations! You have successfully set up a local repository and pushed it to a remote server on GitHub. Resources and Further Reading ============================= If you want to learn more about Git and GitHub, here are some resources to help you get started: - `GitHub Guides `_: Official guides and documentation from GitHub. - LinkedIn Learning Course: - `Git from Scratch `_: A comprehensive course on Git fundamentals and best practices. - `Learning Git and GitHub `_: A course that covers the basics of Git and GitHub. - `Git Essential Training `_: A comprehensive course on Git version control.