Uploading Local Files to GitHub and Updating Them
GitHub, a widely-used platform for version control and collaboration, offers a simple yet essential function: uploading your local files to a repository and updating them as your project progresses. If you’re new to GitHub and wondering how to get started with uploading and updating files, this guide is for you!
Using Git commands offers more control, helps understand version control deeply, and allows for efficient handling of complex tasks compared to the GitHub interface, which is easier for basic operations.
Before You Start: Ensure Git is Installed
Before diving into uploading files to GitHub, make sure Git is installed on your computer. You can download and install Git from git-scm.com if you haven’t already.
Now, let’s proceed with the guide to upload your files to GitHub and maintain their updates.
Step 1: Setting Up a New Repository on GitHub
- Create a New Repository:
- Sign in to your GitHub account.
- Click on the “+” icon in the top right corner and select “New repository.”
- Give your repository a name and a brief description.
- Choose to make it public or private (based on your preference).
- Click on “Create repository.”
Step 2: Uploading Files to Your New Repository
- Initialize Git in Your Local Project:
- Open your terminal or command prompt.
- Navigate to your project directory using the
cd
command.
2. Initialize a Git Repository:
- Type
git init
and hit Enter. This initializes a new Git repository in your project folder.
3. Add Your Files:
- Use the command
git add .
to add all files in the directory to the staging area.
4. Commit Your Changes:
- Enter
git commit -m "Initial commit"
to commit the changes to the repository.
5. Link Your Local Repository to GitHub:
- Go back to your GitHub repository page.
- Copy the repository’s URL.
- In your terminal, type
git remote add origin <repository URL>
and press Enter.
6. Push and Pull Your Files to GitHub:
- Then, execute
git pull origin master
to pull your local files. - Finally, push your files to the GitHub repository by executing
git pull origin master
. It might ask for your credentials.
Step 3: Updating Files on GitHub
- Make Changes Locally:
- Edit or add new files in your local project as needed.
2. Stage and Commit Changes:
- Use
git add .
to stage the changes. - Commit the changes with
git commit -m "Brief description of changes"
.
3. Push Changes to GitHub:
- Once again, push the changes with
git push
.
To summarize:
Uploading files to your new repository:
cd your_project_directory
git init
git add .
git commit -m "Initial commit"
git remote add origin <repository_URL>
git pull origin main
git push -u origin main
Updating Files on GitHub:
# Make changes locally in your project
# Stage, commit, and push changes to GitHub
git add .
git commit -m “Brief description of changes”
git push origin main