How to Utilize GitHub
When I first started coding, I had no idea what GitHub was. And the amount of open source code on it and the amount of time and mental stress it can save you. I’m going to give you git features and terminal use that can help you.
Commit early, commit often
You’ll learn that committing can save you A LOT of time. With coding, you’re always tinkering and moving code around or refactoring your code. And more often than not, that can result in your app to completely blow up in your face. Committing to GitHub, gives you a safety net to go back to if your tinkering does blow up.
Heres some code to commit to your GitHub Repo.
- git add .
- git commit -m “Change titles and styling on homepage”
- git push
Make sure that your cd into the correct directory!
Create a Separate Branch
Creating a branch is a great way also to be able to save your self time and stress. It allows you to work on your code with no cares of messing everything up. Especially if you’re working with a group, if everyone has there own branch, you can all commit your branch and merge it with the master.
Heres some code on how to create a new branch for your GitHub Repo.
Note
Creating a new branch and switching to it at the same time
It’s typical to create a new branch and want to switch to that new branch at the same time — this can be done in one operation with git checkout -b <newbranchname>
.
From Git version 2.23 onwards you can use git switch
instead of git checkout
to:
- Switch to an existing branch:
git switch testing-branch
. - Create a new branch and switch to it:
git switch -c new-branch
. The-c
flag stands for create, you can also use the full flag:--create
. - Return to your previously checked out branch:
git switch -
.
Learn How to Search GitHubs Open Source Code
The amount of open source code that is on GitHub is INSANE.
You can filter repositories based on time of creation or time of last update. For repository creation, you can use the created
qualifier; to find out when a repository was last updated, you'll want to use the pushed
qualifier. The pushed
qualifier will return a list of repositories, sorted by the most recent commit made on any branch in the repository.
You can search repositories based on the main language they’re written in.
You can search repositories by the number of topics that have been applied to them, using the topics
qualifier along with greater than, less than, and range qualifiers.
You can search for commits globally across all of GitHub, or search for commits within a particular repository or organization. For more information, see “About searching on GitHub.”
When you search for commits, only the default branch of a repository is searched.
To search commits in all repositories owned by a certain user or organization, use the user
or org
qualifier. To search commits in a specific repository, use the repo
qualifier.
There is SO much more you can do with GitHub. These are just the beginning of the Ice-burg that GitHub has to offer. So I’d recommend taking the time to really understand the effective and efficient ways GitHub can help you!