If you have local work sitting in a branch and you want to send it to GitHub without causing a small office incident follow along. This short command line tutorial covers creating or switching to a git branch staging and committing your changes adding a remote if needed and pushing the branch so other humans can review your glorious code.
Make a branch name that actually explains what you did unless you enjoy future archeological digs. To create and switch in one step run
git checkout -b my-branch
To switch to an existing branch do
git checkout my-branch
Use readable names that help your team and your future self. This is version control not treasure hunting.
Stage everything or pick files like a responsible developer. On the command line use:
git add .
to stage all changesgit add path/to/file
to stage specific filesThen commit with a clear message that explains what changed. For example
git commit -m "Describe the change briefly"
Good commit messages save hours of confusion later. Bad commit messages are a public service announcement for chaos.
If your local repository has already been linked to a remote you will see it with
git remote -v
If nothing shows up then add your GitHub repo as a remote. Replace the URL placeholder with your repo URL
git remote add origin <your-repo-url>
That configures the git-remote named origin which is the usual shorthand for the remote repository on GitHub.
To publish the branch and set upstream tracking so future pushes and pulls are simpler run
git push -u origin my-branch
The -u option tells Git to remember that origin/my-branch is the upstream for your local branch. After that you can just run git push
or git pull
without repeating names.
If GitHub refuses your push with a permission error authenticate using an SSH key or a personal access token depending on your setup. Both methods work. If you get stuck the GitHub docs have step by step guides and your keyboard can be used for pleading.
git status
before pushing to confirm you are on the right branch and have staged the intended filesOnce the branch is on GitHub you can open a pull request or ask a reviewer to look. Pushing a branch is the minimum viable collaboration step in modern version control. Congratulations you have shared code with the world and possibly started a lively code review conversation.
That is all you need to push a local git-branch to a remote repository on GitHub using the command-line. Follow these steps and you will avoid the most common mistakes while keeping your workflow sane and slightly less dramatic.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.