| by Arround The Web | No comments

Add a File to GitHub Using Git Bash

Git is the most commonly used versioning control system among the developer’s community. Developers create projects locally and push data through Git bash to the remote repository, which is the GitHub hosting service for collaborating with other project members. More specifically, pushed data includes project source code files and the folder.

In this blog, we will learn the easier procedure to add a file to GitHub using Git bash.

How to Move a File to GitHub Using Git Bash?

Sometimes, you may need to add a file to a remote hosting service using the Git bash terminal. To do so, move to the Git repository and initialize it. Then, create and track to the staging area. Next, commit the added changes and clone the remote repository. Lastly, add the local file to the remote by utilizing the “$ git push -f remote <local-branch>” command.

Now, let’s implement the above-discussed procedure!

Step 1: Move to Git Repository

First, run the “cd” command to navigate to the desired local repository:

$ cd "C:\Users\nazma\Git\Demo3"

Step 2: Initialize Directory

Initialize the Git repository by utilizing the “git init” command:

$ git init

Step 3: Create File

Run the following command to create a new file in repository:

$ touch file3.txt

Step 4: Track File

Now, track the newly created file from working directory to the staging area:

$ git add file3.txt

Step 5: Commit Changes

Save the added changes to the local repository using the “git commit” command with the message:

$ git commit -m "new file added"

In the above command, the “-m” flag is utilized for specifying the message:

Step 6: Clone Repository

Next, clone the remote repository to the local repository:

$ git clone https://github.com/GitUser0422/demo3.git

Step 7: Push Branch

Push the local branch with added changes to the remote repository using the following command with the “-f” option and remote name:

$ git push -f origin master

Lastly, go to the remote repository and ensure that the file is pushed to the remote repository:

We have offered a method to add a file from Git bash to GitHub.

Conclusion

To add a file to GitHub using Git bash, firstly, move to the Git repository and initialize it. Next, add and track a new file to the staging area. Commit made changes and clone the GitHub repository. Lastly, execute the “$ git push -f remote <local-branch>” command to push the local branch to GitHub along with the files. This blog demonstrated the easier procedure to add a file to GitHub using Git bash.

Share Button

Source: linuxhint.com

Leave a Reply