Clone Repository & Push Changes using Git Bash

There are two methods I use to push code to GitHub.  Method 1. Visual Studio Code.  Method 2. Git Bash.  Both are effective and I know people who use one over the other all the time.  In this article I will walk through cloning your repo in GitHub locally via SSH, clone the repo, and then push changes to your GitHub repo via Git Bash.

This walkthrough assumes Git Bash is available. If it is not, install Git for Windows first.

If you are looking for my blog article on how to do the above via Visual Studio Code, please go to this URL:
https://digitalthoughtdisruption.com/2020/09/09/clone-repository-push-changes-using-visual-studio-code/

If you are looking for an article on how to create the GitHub repository please see the following link:
https://digitalthoughtdisruption.com/2020/09/09/create-a-repository-in-github/

Step by Step Process:

Clone GitHub Repository Locally and Push Changes via Git Bash

Screenshot from the Clone and Push a Repository With Git Bash walkthrough at step 1; the adjacent article text explains that clone GitHub Repository Locally and Push Changes via Git Bash.

We are going to want to make sure we have Clone with SSH select

Copy to clipboard

Screenshot from the Clone and Push a Repository With Git Bash walkthrough at step 2; the step instructs the user to copy to clipboard.

$ git clone <contents of clipboard>

This command will pull down a copy of the repo living on GitHub

Screenshot from the Clone and Push a Repository With Git Bash walkthrough at step 3; the adjacent article text explains that this command will pull down a copy of the repo living on GitHub.

$ ls

This will show that the repo has been successfully cloned locally

Screenshot from the Clone and Push a Repository With Git Bash walkthrough at step 4; the adjacent article text explains that with a simple search in explorer and a la -la command you can see all the files that are in the repo.

With a simple search in explorer and a la -la command you can see all the files that are in the repo

Screenshot from the Clone and Push a Repository With Git Bash walkthrough at step 5; the adjacent article text explains that with a simple search in explorer and a la -la command you can see all the files that are in the repo.

For the sake of demonstration I created three quick empty files so I have something stored locally

$ git status

This command showed that there have been some changes made that are current not being tracked

Screenshot from the Clone and Push a Repository With Git Bash walkthrough at step 6; the adjacent article text explains that this command showed that there have been some changes made that are current not being tracked.

$ git add .

This command will add all files in this directory

$ git status

This will now reflect we have added the files to be tracked and are awaiting a commit

Screenshot from the Clone and Push a Repository With Git Bash walkthrough at step 7, showing s git commit -m “random files saved; the adjacent article text explains that this will now reflect we have added the files to be tracked and are awaiting a commit.

$ git commit -m “message”

This command now commits the new files but GitHub is still unaware of this commit, so now we need to push the files up to the central repo

Screenshot from the Clone and Push a Repository With Git Bash walkthrough at step 8, showing Is git push origin master; the adjacent article text explains that $ git push origin master.

$ git push origin master

This will now push the changes up to the GitHub Repo

Screenshot from the Clone and Push a Repository With Git Bash walkthrough at step 9; the adjacent article text explains that this will now push the changes up to the GitHub Repo.

If we go back to the GitHub page & refresh you should see the new files and their comment on the main repo page

You can also see that a new commit has been applied

Summary:
It is not difficult to use the Bash in order to push and pull down files.  In my next article I will show how to perform these same methods but within VS Code.  As always, I hope y’all found this useful.

Continue reading

Fetch vs Pull with Git Bash

Explore another guide in this topic and build on what you have just read. Read the article

2 thoughts on “Clone Repository & Push Changes using Git Bash”

Leave a Comment

Discover more from Digital Thought Disruption

Subscribe now to keep reading and get access to the full archive.

Continue reading