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:
Step 2: Initialize Directory
Initialize the Git repository by utilizing the “git init” command:
Step 3: Create File
Run the following command to create a new file in repository:
Step 4: Track File
Now, track the newly created file from working directory to the staging area:
Step 5: Commit Changes
Save the added changes to the local repository using the “git commit” command with the message:
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:
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:
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.