Making your first push in git

Nic Ollis
Nic Ollis
Jun 6, 2016 · 3 min read

Making your first push to a project can be a daunting task if you are new to git. Today we are going to review how I do my checks before pushing and what you can do to avoid making mistakes prevalent to newbies.

For me my first step is always running a git status. I do this so I can get a quick list of files that have been added/modified/deleted. When I code I might put a binding.pry in a file I made no other edits to for troubleshooting and if I see the file in the list it's a good reminder to open the file and remove my changes.

Next we jump into a more detail view git diff, will show you all the changes git has registered. Review each line in detail. Make sure you don't have any commented out code that needs removed, or anything like binding.pry that needs removed. What you see in git diff is what will show on your pull request so make sure you won't be embarrassed by anything on it.

Now that we have all out changes staged and looking good I like to run git add . and git commit -am "<message>" the -a on git commit will make sure you remove any deleted files.

Don’t do your push just yet, we need to make sure nothing has changed on the master branch that could break our code. For this I take a multistep approach, although it could be narrowed down a bit to be more efficient. First I jump back to my local master branch git checkout master then I pull down the remote master git pull.

If changes were pulled down follow this next step otherwise jump to the next paragraph. I then jump back over to my working branch git checkout nic/working-branch and then run a git merge master. The merge will let you know of any conflicts, open any conflicted files and handle the issues as they come up. To leave the commit message screen that opens in vim by default hit :wq and enter on your keyboard. Now our run your test one more time to make sure no changes broke your code.

At this point we have all our changes committed locally and our branch is up to date with everything on the master branch. Next we just need to push the code up to the repository. Best practice it to push the code using your branch so project controllers can test your code easily. git push origin nic/working-branch will push our working branch up to the origin. From here we can log into github and build our pull request!

So to summarize with a quick list.

  • git status and git diff
  • git add . and git commit -am ‘message’
  • git checkout master and git pull
  • git checkout nic/working-branch and git merge (if needed)
  • git push origin nic/working-branch
  • login to github and make pull request

As always thanks for reading, and follow me on twitter for more daily updates, live stream alerts, and post on my journey from Senior IT Admin to Junior Developer. Subscribe to the Program Practical channel on YouTube. Feel free to ask any questions in the comments below, and don’t forget it’s always a good time to start to #LearnToCode

Program Practical

Easy to digest post to help make you a better programmer.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store