Ah git. It's an odd name for a dance number. (Yes it's an odd analogy, just go with it.)
Let's assume you are ready to dance. By that I mean you've gone to GitHub* and found a project. You want to play with the code but aren't looking to contribute. The first steps are Fork and Clone.
You fork the repository in GitHub so you have your own to play with.
You clone your new remote repository from GitHub by clicking the clone button and then copying the link. Then to put it in a local repository, in your terminal you type:
Then change directory (cd the_name_you_copied) and start the dance.
The git dance: Branch, Code cha-cha, Pull, Push, Pull Request, Merge, Pull.
It might seem a little complicated, but it's nothing compared to the electric slide. Plus you can do it sitting down.
Branch: From the master branch (which is the branch you've cloned) you type "git checkout branch new_code". What you are actually telling the computer is "create a git branch called new_code** and then check out - move on to - that branch instead of working on the master branch" - it is quite concise.
Start the Code: Open your project in whichever editor or IDE is your preference. (I'm partial to Sublime Text or VSCode.) Do your code-y-code-code and make sure it doesn't break anything.
Add and Commit makes it a cha-cha:
You type git add the-file-you-are-working-on, then git commit -m "write a good message - your teammates and your future self will appreciate it."
Git add puts the code into a staging area. Git commit changes the code on your branch and saves it to that point in time. ('-m' stands for message.)
The next dance steps are about being polite to your dance partners. No one likes to get their toes stepped on, even metaphorically. Pull, Push, Pull Request, and Merge.
Assuming that you aren't the only one dancing with this code, you type git pull origin master - that pulls from the remote repository. That way any conflicts you might have with the master are resolved on your local repo instead of when you are trying to merge it on GitHub.
Next Push it (real good) by typing git push -u origin new_code. Now the remote copy of the repository has the branch you have been working on.
Then you clickity-click the compare & pull request button MAKE SURE YOU ARE COMPARING WITH YOUR REPO MASTER and ask someone to look at your code. It's always nice to have another pair of eyes check your code is not going to break the master.
Then they Merge it. And now the work you've done is part of the master branch! You've done it. Then switch to master in your local repo (git checkout master) and do a final Pull (git pull) so that the changes are added to your local master branch. And that's the git dance.
Thanks for dancing with me. Now git out there and d̶a̶n̶c̶e̶ code!
*You don't have to use GitHub to use git. In this painfully stretched analogy if git is the dance, GitHub is the dance floor.
**Name your branches after what you intend to be working on. New_code is not a great name.
Erica Forget is a web developer who enjoys pattern recognition, is always learning, and looking to refine her craft. Whether in fiber arts, baking, or coding – everything gets better if you document what works and calculate how to improve the next iteration.
While she staying home with her son, Erica has graduated from Dev Bootcamp as a full-stack Ruby developer. She has supported Women Who Code Austin as an Event Lead for the past two years and contributed to Firefox debugger. Erica holds a BA in Humanities from the University of Texas at Austin.