Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Uploading Projects to GitHub: A Step-by-Step Guide

Tech 3

Git is a free, open-source distributed version control system designed to track changes in files across projects. It allows developers to stage changes and commit them when ready, enabling rollback to previous states. GitHub is a cloud-based platform built on Git, providing hosting for repositories. It serves as a hub for open-source collaboration and offers paid private repositories for proprietary code management.

Installing Git

Download Git from the official website: https://git-scm.com/. Follow the installation prompts, accepting default settings. After installation, right-clicking on the desktop or within a folder should reveal Git Bash and Git GUI options. Git Bash, the command-line tool, is used for GitHub operations. Note that Git's default text editor is Vim, which has a unique interface. Basic Vim navigation will be covered as needed.

Creating a GitHub Account

Visit GitHub at https://github.com/ to sign up. Access may require a VPN depending on your location. Use a valid email address for registration. Once registered, Git allows local operations without constant GitHub login.

Project Upload Workflow

The upload process involves three key stages:

  1. Staging files to a local buffer.
  2. Committing files to the local repository.
  3. Pushing files to the remote GitHub repository. Prior configuration of the local repository is required.

Creating a Remote Repository

  1. From your GitHub homepage, click the + icon in the top-right corner and select New repository.
  2. Fill in the repository name, description (optional), and choose public or private visibility. Initialize with a README is optional.
  3. Click Create repository.

Upon creation, note the default branch name (typically main). The repository page provides the URL needed for linking, available in both HTTPS and SSH formats.

Configuring the Local Repository

  1. Create a new folder on your computer to serve as the local project directory. Avoid using Chinese chaarcters in the path.
  2. Navigate into this folder, right-click, and select Git Bash Here to open the terminal.
  3. Initialize a Git repository in this directory:
    git init
    
    This creates a hidden .git folder.
  4. Configure your Git identity. This can be done by editing the config file inside the .git folder or via the command line.
    • Method A (Edit config file): Open .git/config in a text editor and add:
      [user]
      	name = YourName
      	email = your.email@example.com
      
    • Method B (Command line):
      git config --global user.email "your.email@example.com"
      git config --global user.name "YourName"
      
  5. Link the local repository to the remote GitHub repository. Copy the HTTPS URL from your GitHub repo page and run:
    git remote add origin https://github.com/your-username/repo-name.git
    
    No output indicates success.

Handling Branch Names

Older Git setups may default to master as the primary branch name, while GitHub uses main. To synchronize:

  1. Check existing branches:
    git branch -a
    
  2. Fetch the remote main branch:
    git fetch
    
  3. Switch to the main branch:
    git checkout main
    
    A README.md file from the remote may appear in you're folder.

Uploading Files for the First Time

  1. Stage Files: Copy your project files into the local repository folder. To stage all files:
    git add .
    
    To stage a specific file:
    git add example.py
    
    Verify status with git status.
  2. Commit Files: Commit the staged files with a descriptive message.
    git commit -m "Initial project commit"
    
  3. Push to Remote: For the first push, specify the remote and branch:
    git push -u origin main
    
    Subsequent pushes can use simply git push.

Refresh your GitHub repository page to confirm the files have been uploaded.

Basic Vim Operations in Git Bash

If you accidental enter Vim's edit mode:

  • To exit with out saving: Press Esc, then type :q! and press Enter.
  • To save and exit: Press Esc, then type :wq and press Enter.
  • Copy/Paste: Use right-click in the Git Bash window.
  • Cencel a running command: Ctrl + C.
  • Navigate command history: Use the up/down arrow keys.
Tags: GitHub

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.