The Wayback Machine - https://web.archive.org/web/20240927175120/https://www.geeksforgeeks.org/how-to-push-folders-from-local-pc-to-github-using-git-commands/
Open In App

How to Push Folders From Local PC to GitHub using Git Commands?

Last Updated : 16 May, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Git offers a powerful command-line interface for managing code repositories, understanding how to push folders from your local PC to GitHub repositories using Git commands can enhance your workflow and streamline the process of sharing code with collaborators or deploying projects.

In this article, we’ll see the step-by-step process of pushing folders from your local PC to GitHub using Git commands.

Why Push Folders to GitHub?

Pushing folders from your local PC to GitHub repositories is important for several reasons:

  1. Code Sharing: Uploading folders to GitHub allows you to share your codebase with collaborators, contributors, or the wider community.
  2. Backup and Versioning: By storing your code on GitHub, you benefit from version control, enabling you to track changes, revert to previous states, and maintain a backup of your project.
  3. Collaboration: Pushing folders to GitHub facilitates collaboration by providing a centralized platform for team members to access, review, and contribute to the codebase.

Steps To Push Folders to GitHub

First of all, make sure to install Git on your computer. Now, head toward that folder that you want to push there on GitHub. Then, follow the following steps. 

Step 1. Open Git Bash in that particular folder. Type git init (this will make that folder a repository)

Git initialization

Step 2: Type git add . (this will add all files to the repository)

Git add

Step 3. Type git commit -m “Initial commit msg” (all files now in the repository)

git commit -m “Initial commit msg

Step 4. Type git status (you will get a msg, “On branch master nothing to commit, working tree clean” this shows your local repository is finally created)

git status

These are the steps that are used to make a local repository, now to push the same to a GitHub repository we use the following steps-

Step 1. Open your GitHub profile and create a New Repository. Copy the SSH Key of that created repository.

creating new repository

Step 2. Open Git Bash in that particular folder that you want to push. Type git remote add origin PASTE_SSH_KEY_OF_CREATED_REPO. Then type git push origin master –force (type ‘main’ in place of the ‘master’ if your default branch is master). Please refer to the following picture (if needed):

How to Push Folders From Local PC to GitHub using Git Commands?

Now, refresh your Github page, you will be able to see your committed folders/files there.



Similar Reads

Difference Between Git Push Origin and Git Push Origin Master
Understanding the difference between git push origin and git push origin master is important for efficient version control in Git. These commands are used to upload changes from your local repository to a remote repository, but they function differently. This article will explain these differences, how each command works, and when to use them. What
3 min read
Use of Folders and Sub-folders in Postman Collections
In API testing and development, it's crucial to keep things organized for smooth workflows. Postman Collections, a handy feature in the Postman tool, help you stay organized by grouping API requests. They go a step further by allowing you to use folders and subfolders for even better organization. In this article, we'll dive into how folders and su
3 min read
How to Authenticate Git Push with Github Using a Token?
As GitHub has transitioned away from password-based authentication, using tokens for operations like pushing to repositories is now the recommended approach. This method enhances security and aligns with modern best practices. This guide will walk you through the steps to authenticate your Git push commands using a personal access token. Steps to A
3 min read
How to Push Anything to GitHub using Git Bash?
GitHub has become the go-to platform for collaborative software development, offering powerful tools for version control, collaboration, and project management. Git Bash, a command-line interface for Git on Windows, provides a quick way to interact with GitHub repositories. In this guide, we'll learn about the process of pushing anything to GitHub
3 min read
How to Push a Local Branch to a Remote Repository in Git?
Git is a popular version control system that allows you to track changes in the codebase and collaborate with others. One of the common tasks in Git is pushing a local branch to a remote repository. This article will guide you through the steps to achieve this. Pushing Local BranchPushing a local branch to a remote repository involves creating a br
2 min read
Difference Between "git commit" and "git push"?
Git commit and git push are two essential commands you'll use a lot when working with Git. even their frequent use together, they have different functions. In order to help you understand when and how to use these two commands effectively in your version control workflow, this article will break down their differences. What is git commit?git commit
2 min read
Difference Between Git remote prune, Git prune and Git fetch --prune
Git is a version control system that helps developers manage and track changes in their codebase. Among its many commands, git remote prune, git prune, and git fetch --prune are essential for maintaining a clean and organized repository. This article will explain the differences between these commands, their syntax, uses, and provide examples to il
4 min read
Ignoring Files and Folders in Git
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git relies on the basis of distributed development of software where more than one developer may have access to the source code of a specific application and can modify changes to it that may be
11 min read
How to Ignore Folders and Directories in Git with .gitignore?
Git is a powerful and widely-used version control system that allows developers to track changes in their codebase, collaborate seamlessly, and maintain a robust history of their projects. It was created by Linus Torvalds in 2005, Git has become widely accepted for version control in the software development industry. In this article, we will learn
4 min read
How to Push Code to Github using Pycharm?
Git is an open-source version control system. It means that whenever a developer develops some project (like an app or website) or something, he/she constantly updates it catering to the demands of users, technology, and whatsoever it maybe, Git is a version control system that lets you manage and keep track of your source code history. Let’s say y
2 min read
Push Codes from Linux (UBUNTU) To GitHub using SSH KEY
GitHub, one of the most popular platforms for version control and collaboration, offers multiple authentication methods for interacting with repositories. SSH keys provide a secure and convenient way to authenticate and push code from a local machine to GitHub. In this article, we'll learn the step-by-step process of pushing code from Linux (Ubuntu
3 min read
How to Clone Github Repository and Push Changes in Colaboratory?
If you are working with a Machine Learning project, the greatest bottleneck could be the lack of computational resources. With Google Colaboratory (Google Colab or Colab in short), now we have the freedom to use a GPU at your disposal. Here we are going to see how we can clone your GitHub repository into the Google Colab. To do so follow the below
2 min read
How to Push a Project and Contribute on GitHub?
GitHub is a powerful platform for hosting and collaborating on code repositories. Whether you're working on an open-source project or collaborating with a team, knowing how to push a project and contribute on GitHub is essential. This article will guide you through the steps to push your project to GitHub and make meaningful contributions. Table of
5 min read
How To Push A Big Next.js App To GitHub?
Managing a big Next.js and version control of the deployed Next. js application could be challenging sometimes, especially when it comes to file size and repository issues. This guide will help you no matter if you are an experienced programmer or a person who never used GitHub at all. It explains how to push a large Next application to GitHub effi
3 min read
How to Generate Public SSH or GPG Keys Using Git Commands?
Generating public SSH or GPG keys is important for securing your Git operations and ensuring the authenticity of your commits. In this guide, we'll walk you through the process of generating these keys using Git commands, making it easy to track along and understand. What Are SSH Keys?SSH (Secure Shell) keys are a pair of cryptographic keys used to
2 min read
How to Push Git Branch to Remote?
Git is the most popular version control system which records the changes made to our project over time in a special database called a repository. We can look at our project and see who has made what changes when and why and if we screw something up we can easily revert our project back to an earlier state. In this article, we will see the essential
6 min read
What is Git Push?
Pre-requisite: Git Using the git push command, you can upload your files available on your local machine to the remote repository. After git pushes the changes to the remote repository other developers can access the changes and they can contribute their changes by git pulling. Before pushing it to the remote repository you need to do a git commit
8 min read
How to Create a New Branch in Git and Push the Code?
Branching in Git is a helpful feature for software developers working on a big team project. It allows the team members to work on different aspects of the software by creating a branch from the main branch. The main branch is not affected by the changes in the created branch until it is merged into the main branch. Once, work is complete for the b
8 min read
How to Push Git Tags to Remote Repository?
Git tags are references to specific points in Git history and are used to mark release points (like version numbers). Pushing Git tags to a remote repository is important for sharing these release points with collaborators or deploying releases to production environments. In this article, we'll explore the process of pushing Git tags to a remote re
3 min read
How to Push an Empty Commit in Git?
In Git, commits are snapshots of your repository at specific points in time, typically containing changes to the files. However, there are instances when you might need to create and push an empty commit, one that doesn’t introduce any changes to the codebase. This article explains why you might need an empty commit and how to create and push one i
3 min read
How to Force Git Push?
Git is a powerful version control system that helps developers manage and track changes in their codebase. Sometimes, you might need to force push changes to a repository to overwrite previous commits. This article will guide you through creating a GitHub account, setting up a repository, deploying a website, and understanding how to force push in
6 min read
How to Change a Git Commit Message After a Push?
Accidentally deleting a branch or commit in Git can seem alarming, but Git's powerful version control capabilities often allow you to restore them with relative ease. This guide will walk you through the steps to recover a deleted branch or commit. Table of Content Restoring a Deleted BranchUsing GitHub or GitLabRestoring a Deleted CommitUsing git
3 min read
How To Push a Specific Commit to Remote in Git?
In version control systems like Git, pushing specific commits to a remote repository is a common task. Whether you're working on a feature branch or fixing a bug, sometimes you need to push only a particular commit without including earlier commits. Here, we'll explore the steps and commands to Push a Specific Commit to Remote in Git. Understanding
3 min read
How To Resolve "Git push rejected after feature branch rebase"?
Rebasing feature branches in Git can lead to a cleaner commit history and better integration with the main branch. However, it's not uncommon to encounter rejections when pushing rebased branches due to conflicts with remote changes. In this article, we'll explore the common causes of "Git push rejected after feature branch rebase" errors and provi
3 min read
Default Behaviour Of "git push" Without A Branch Specified
When working with Git, understanding how Git push operates without specifying a branch can prevent many potential pitfalls in version control. This article will guide you through the default behaviour of Git Push Without A Branch Specified. What is git push?git push is a fundamental Git command used to upload local repository content to a remote re
3 min read
How to Fix Git Error: 'failed to push some refs to remote'?
When working with Git, you might encounter the error message: "failed to push some refs to remote." This error typically occurs when your local repository is out of sync with the remote repository. This article will guide you through the steps to resolve this issue and successfully push your changes to the remote repository. Common Causes of the Er
3 min read
Git Push
Version control and collaboration are vital elements of any Git project. Git push is one of the most important commands in the Git ecosystem. You can make your updates accessible to others by sending your committed changes to a remote repository. The git push command, all of its options, and recommended practices will be covered in detail in this a
5 min read
How to Upload a Project through GitHub Desktop on GitHub
GitHub Desktop is a user-friendly application that simplifies the process of managing your GitHub repositories on your local machine. If you’re looking to upload a project to GitHub using GitHub Desktop, this guide will walk you through the steps, making the process straightforward and accessible even for beginners. What is GitHub Desktop?GitHub De
3 min read
How to Clone Web Project From GitHub in Pycharm Using Git?
PyCharm is one of the most popular Integrated Development Environments (IDEs) for Python development. It provides robust support for version control systems like Git, making it easy to manage your code and collaborate with others. Cloning a web project from GitHub into PyCharm is a simple process that can significantly streamline your workflow. Thi
1 min read
How to Add Images on README .md File in a GitHub Repository From the Local System?
Adding images to your README.md file in a GitHub repository can significantly enhance the project documentation. Whether you're showing screenshots, diagrams, or other visuals, including images can make your README more engaging and informative. This article will guide you through the process of adding images to your README.md file from your local
2 min read
Article Tags :