GIT that Repo…
By: Mai Pham
Tags: Flatiron, Repositories, Branching, Git, Programming

To begin…

You start your first week at your new job and or coding school and they tell you to clone down a repository from GitHub and start working on a project. What do you do? (Here, I am using GitHub as an example but there are many other services that host Git repositories.)

You go to that repository on Github and you click on the green button in the upper right corner that says “Code.” This is the start of cloning the repository to your local environment.

Click on the Code button will enable a drop down box where you can copy the link under SSH. You can also click on the clipboard icon to copy the link.

After copying the link in the SSH field, you go to your terminal, into your directory where you want to save this project on your computer.

git clone <paste-the-url-here> // this will clone the repository in the directory of your choosing

Once the cloning is complete, you don’t want to start working on it.

Rule of thumb: NEVER WORK ON THE MASTER BRANCH

… as this will cause a lot of issues especially if there are multiple collaborators working on the same repo. Instead, in your terminal, create a new branch by:

This command will create a new branch and switch you from master branch into that new branch

Once you are on the branch you just created, you may open up your VSCode (or whatever program you are using to code). After you have done some amazing work on it, you want to proceed by staging your modifications:

This command will stage and “add” any changes you’ve made to the repository

git status // running this will list files in green if you have successfully “added” and “staged.” It will list files in red if it has not been successful. If it is in red, run git add . again

Once everything has successfully been staged, you are ready to commit! Kind of like committing your life away to someone… just kidding.

This command will store all the added changes to your branch. You are committing to your changes. -m means that a message will follow. Create a meaningful message that will allow your colleagues and collaborators know what you added to that commit.

Now that you’ve committed, what is next? Before pushing, you must merge the changes you’ve made on your branch to the master branch. To do this, you must switch to the master branch first by..

This command will put you onto the master branch…

To check to see what branch you are on, run ..

git branch // this will show you which branch you are on with an * next to the branch name in your terminal

Once you are certain you are on the master branch, you are ready to merge!

git merge <the_branch_you_just_worked_on> // this will merge all the changes from that branch onto the master branch.

Now you are ready to push the repo up…

git push origin master // this will push all your work you’ve done onto the git repo from where you cloned.

Voila, you are done! you’ve clone, modified, staged, committed and pushed your first repo!! Lets say your colleague did some work on their own branch and pushed it up, to pull their changes down, you just need to go into the same directory where you cloned the repo down the first time and run