Introduction
Pushing is the process of uploading a folder saved on a local repository to an online repository which can be accessed remotely. The online repository may be public or private.
This article is a step by step explanation of how to push projects from your local folder to GitHub on windows operating system. We shall use GitBash to write command line instructions and SSH key to securely link our GitHub account to GitBash without needing to type a username and password every time we push.
By end of this guide, you will be able to create a project folder, initialize it as a Git repository, connect it to GitHub over SSH and push your work online.
What is Git, GitHub, GitBash and SSH?
Git is a control software which tracks changes to files over time, letting you save edits (commits) and go back to earlier versions.
GitHub is an online platform that hosts Git repositories. This is where your pushed documents are found and it enables access to your documents remotely and by other people.
GitBash is a terminal that lets one run Git commands in a command line language environment.
SSH(Secure Shell) is a key that lets your computer to communicate with GitHub securely. This connection enables GitBash to push or pull without the need for prompting.
Prerequisites
Before starting the push process, make sure you have the following:
- Log in to your GitHub account. If you don’t have one, create it at GitHub.com.
- Download GitBash from the official GIT website.
- Correctly configure GitBash with your identity by running the command git config –global user.name “Your Name” and git config –global user.email
"[email protected]". This information is attached to every commit you make so GitHub and your collaborators know who the author is. - To set up your branch use the command git config —-global init.defaultBranch main
- Confirm that your configuration was saved correctly by running git config –global –list. It should appear as below.
Setup your SSH key.
This is the step that allows your computer to communicate with GitHub. You only need to do this once.
- Open GitBash and generate a new SSH key, replacing the email with the one linked to your GitHub account using the command ssh-keygen -t ed25519 -C “email”
- Confirm the key was created using ls -al ~/.ssh
- You should see the following files:
- id_ed25519(This is your private key, do not share it with anyone.)
- id_ed25519.pub(This is your public key)
To display the SSH key use cat ~/.ssh/id_ed25519.pub and then highlight the entire output and copy it.
On GitHub, go to Settings then SSH and GPG keys where you will select new SSH key. Give it a descriptive title and paste your public key into the key field and add SSH key.
- Test the connection on GitBash using ssh -T
[email protected]
Creating a local project folder and documents
If you don’t have a project folder, here is how to create one.
- Navigate to the location where you want to save the project(we will use the desktop as an example) using the command cd ~/Desktop
- Create a new folder for the project using mkdir my-first-project (Note: spaces will not work unless you use speech marks “”)
- Move into that folder using cd my-first-project
- Create a new document inside the folder. Use the command touch README.md
- To confirm that the document is within the folder use the command ls
- To add content to the document you can either use the command echo “Text” >> README.md
- For longer text, open an editor using the command nano README.md. Save the work using Ctrl+O and then close it using Ctrl+X
- Use the command cat README.md to view what has been added.
Push Process
- Confirm your current working directory by running the command pwd
- Use the command ls -la to see all files hidden and non-hidden files.
- If you are not in the directory of the folder you are looking for, use the command cd to move until the correct directory.
- Initialize the directory a GIT repository so GIT may begin managing the project using the command git init
- Stage your file so Git starts tracking using the command git add .
- Commit the staged files with a message describing the changes using git commit -m “description”
- Open GitHub and create an empty GitHub repository, name the repository, leave README off and then choose the visibility of your repository. Afterwards, click create repository
- Under quick setup, select SSH as your connection option.
- Copy the SSH repository address and then on GIT bash, type the command git remote add origin pasted SSH repository address
- Confirm the remote is correct using the command git remote -v (This displays the URL you just added)
- You can now push the project using git push -u origin main(The -u flag sets origin main as the default)
- Refresh the repository page on GitHub to see your pushed folder
Verifying your push was successful
A quick check to confirm your push actually worked.
- Run the command git status in GitBash. If everything is pushed correctly, you should see the following message, “Your branch is up to date with ‘origin/main.”
- Run the command git log —-oneline to see the commits history.
Conclusion
This is the entire workflow of creating a project, setting up SSH and pushing a local project to GitHub using SSH on Windows. Setting up the SSH key is a one time process and you won’t have to re enter the credentials every time you push. This is the cycle which you will repeat for every change you make.














