Git Serious: A Guide to Starting Your Next Project on Github
Tales From a Gitwit
Software developers from any background and experience level will most certainly have dealt with Github at some point. The online code-hosting platform is the most popular way for developers to collaborate on projects across the globe. Upon first dealing with Github while attending a coding bootcamp, I didn’t grasp how necessary it would be to understand proper procedure and flow moving forward in my new career.
The first step is to go to github.com and create a free account. This is pretty straightforward so we will skip to the next step which is creating a repository for you new project.
Creating a Repository
When you get ready to start your new project, the first thing you need to do is create a new repository (or “repo”). A repository is a place for all files associated with a single project. At the top right of the Github navbar you will see a plus sign next to your profile avatar. Click on the down arrow and you will see a menu with several options. We want to select “New Repository”.
When creating a new repository we must give it a name. Lets make one called awesome-project
You will notice there are several options you can choose when creating a new repository. For now we are just going to make a Public repo since there isn’t anything at all sensitive I want to keep close to the chest. You can also initialize the repo with a README file which is recommended since chances are you want to describe dependencies and version control at some point to another user or developer. Once all desired fields are selected click Create repository.
After you will see a page detailing the next steps. But first we need to talk about branches.
The Master Branch
When a new repository gets created it comes with a default branch called the “main” or “master” branch. This master is used to hold the most recent version of your (hopefully) working code. This is basically a snapshot with which you can make other branches off of. When you create a new branch, you make a copy of the master, allowing you to write new code without directly affecting the master branch itself until the code is approved and working.
Initializing Your Files
So now we have that out of the way we want to setup our existing project to commit to the desired git repository. In the next window we see this box
This tells you exactly what to type into the command line to get your project on Github. Remember to navigate into the directory holding your project before you do this.
When you want to start adding changes to a branch you must type
in the command line. This will give you the ability to add, commit, and push changes to the branch.
I almost always start with creating a new branch.
if you type
into the command line you will see a list of branches with an asterisk denoting the branch you are currently on. You should see you that you are on the lone branch master at this point to lets create a new one by typing:
git checkout -b new_branch
Now you have created a new branch (called new_branch) and have switched over to it off of the master. To confirm you can type in git branch again to make sure. From here we add code to our project. When we are done with our new feature or component or whatever we have a couple options:
is a great way to compare the files you’ve created or modified against the master copy you currently have. Any files you haven’t added to commit will appear in red while those you have staged for commit with appear in green.
Now we can
git add .
to add all of the files for staging to commit (if we type in git status now we see all of these files have turned to green).
The next step is to commit these changes with a message, some description as to what the changes are:
git commit -m "some message about the change"
The last thing to do is push to the master branch:
Finishing the Process
After we push to github we can go to our project repository on the site and see that a change is pending. Click the green Merge pull request button to merge the changes into master. If everything is right you should see this.
And there it is! You’ve committed your first change to Github.
There are literally books dedicated to the ins and outs of Github. This is just meant to be a basic intro to get you started. Take your time and do some experimenting with something simple and fun and you will have the basics of Git flow down before you know it!