GitHub Publish a New Repo with Git CLI Cheat Sheet
This is a quick post to show the steps to publish a new project to a GitHub repo with the Git CLI.
It's a common task for many developers, I go through these steps almost every week so I thought I'd put together a cheat sheet as a reference.
Git CLI: The command line interface for creating and performing actions on git repositories, there are versions for macOS, Linux/Unix & Windows, and can be downloaded for free at https://git-scm.com/downloads.
Create a new GitHub repository
Login to GitHub and create a new repo for your project at https://github.com/new.
Create a new local Git repo and push it to GitHub
Run the following commands from your project root folder to create a new local Git repository, commit the code and push the repo to GitHub.
Create a new Git repo for the project
Add all files to the Git repo
git add -A
Commit all files with the message 'initial commit'
git commit -m 'initial commit'
Connect the local Git repo to the remote GitHub repo
git remote add origin [email protected]:<username>/<repo name>.git
Push all code on the default branch to GitHub
git push origin master
Push new code changes to GitHub
Now that your local Git repo is connected to GitHub, you can push new changes with the following commands.
Add all changes to the Git repo
git add -A
Commit all changes with the message 'updated code'
git commit -m 'updated code'
Push all changes to GitHub
These are on a few of the many
git commands available, a complete reference can be found at https://git-scm.com/docs.
Need Some Git Help?
Search fiverr for freelance Git developers.
Follow me for updates
When I'm not coding...
Me and Tina are on a motorcycle adventure around Australia.
Come along for the ride!