All Things Git You Can Absolutely Get Right the First Time

Updated on November 14, 2018
Lovelli Fuad profile image

By no means a coding master, these are some of the gold nuggets she's encountered in her code adventures. "Doing-it-meself," Lovelli says :)

What better fork guide do you need than a GitHub chef?
What better fork guide do you need than a GitHub chef? | Source

The thing about Git is even though you have no clue how it does what it does, you can still get everything right. And even if you know how everything works, you can still get every single thing totally wrong. I had to learn Git and use GitHub when I worked on a data science project, and just like everyone, I dreaded it from day one.

As soon as the course is completed, I uninstalled Git for Windows from my desktop and only used the GitHub repository to slowly make sense of GitHub Pages to host my own personal website, which is still a work in progress. (Trust me, it looks a lot better now.) I created this hub based on all the little things I didn’t get right when I first tried Git, but could’ve.

  1. How to learn git, or should I learn GitHub instead?
  2. No resets: setting up username and email
  3. Save a repo elsewhere
  4. Add a commit message, and then edit it!
  5. Find out where you are

In addition, if you need to display your code on a Word doc, you might also find this hub useful:

1. Git Makes More Sense When You Understand __________

Installing Git is the easy bit. Once you've got it in your machine comes the difficult part: how do you learn Git? For me, it was not a choice.

There is no wrong way to learn Git, but I am convinced that there is a right way. And it’s not learning by doing. That goes without saying. What I mean is to learn to think within a mindset that makes it easier to understand these new concepts. What I mean is to know what it is not.

How quickly can you learn Git?

Guides and how-tos are a good place to start learning about Git and GitHub. Git website has some comprehensive getting started guide; GitHub learning lab now has plenty of courses to learn to use the platform. But when you’re under a deadline and can’t tolerate technical drawings or jargons yet, it’s a good idea to find solace in the words of other coders and developers who have tried them before you. You can probably understand Git in just a few lunches.

Coding courses

Each code school will have its own tutorial, either in the form of a free course or a resources article. Some good ones are from Codecademy, Pluralsight (previously Code School), and Git Tower. Others are from the source code hosts: Bitbucket, GitLab, Digital Ocean. One long article is usually enough to get acquainted with Git and GitHub, except when you need more.

Other resources for first-timers:

  • Try Git: All of the learning materials are now put in one page on Try Github.
  • Learn Enough: A tutorial of tutorials with one part dedicated on how to learn enough Git to be dangerous.
  • How to GitHub: A tutorial from Gun.io
  • Think Like (a) Git: An entire website dedicated to helping you think like Git
  • Git Immersion: A tour that walks you through the fundamentals of Git
  • Articles: Getting Started with Git and GitHub by Codecademy1, An Intro to Git and GitHub for Beginners (Tutorial)2, A Beginner’s Tutorial to Git and GitHub3, etc.

Read about other things, too!

It seems that coders are realizing that once you understand the concept of X [insert another idea here], Git starts to make more sense. Years after learning Git, people are saying, for example, an understanding of the motivation behind Git’s design can help you learn it. Or, an understanding of why some commands worked, and some others don't.

Take a Quiz About Git: What It Is and Isn't

view quiz statistics

2. No Resets! Setting Up Global Username and Email

Before starting with any new projects, you’ll have to set up a global username and an email. It’s part of the getting started phase. Now this should be easy-peasy, but I actually had to try this several times to get right. The initial setup looks like this:

$ git config --global user.name "Your Name"
$ git config --global user.email "youremail@domain.com"

The first important thing is your user name is your name, not your GitHub username (although it could be). Get this setup right the first time, because this information will be used for every single repo you work on. Although I'm pretty sure there is a way to reset this, it's already too much for first-timers to be dealing with. Ditch the "--global" attribute to set up a username and an email for a single repository. Write down your name and email–along with the quotation marks–into the command line, like so:

$ git config user.name "Anonymous Blocks"
$ git config user.email "anon@blocks.org"
Scribbling on a paper notepad during a coding event as a way to make sense of social coding.
Scribbling on a paper notepad during a coding event as a way to make sense of social coding. | Source

3. Clone That Repo Elsewhere

It’s frustrating to see new folders appearing randomly inside the C: directory. Sometimes when the cloning is done, I am left with the sad feeling of not organizing my project folders appropriately. It's what some might call feeling "disempowered". I didn’t know where the new cloned folder would pop up because I didn’t set it up to a specific path. I still don’t know how to do this, but I’ve learned that there is a way to organize your cloned repos: put them inside a separate folder!

The following code creates a folder named "Clones" inside the Downloads folder in the D: directory, and then clones a repo into that new folder. So the next time you clone a repo, you can save it into a new folder that you create manually beforehand. Maybe inside the Clones folder you want "Repo-1", "Repo-2", "Repo-3", and so on.

$ cd D:/Downloads
$ mkdir Clones
$ git clone https://www.github.com/username/repo-name.git D:/Downloads/Clones

Clone only a branch of the repo

In addition, if ever you need to clone only a certain branch of the repo, you can get that right on your first try, too. I've had one occasion when I didn't need the master branch and only needed to work on one of the branches. Although I didn't push that change, I learned that this code could make it happen (just specify a directory at the end if you need it inside a set folder):

$ git clone --single-branch –b branch-name https://www.github.com/username/repo-name.git 

4. Add a Commit Message, and Make Edits

Saved changes on GitHub are called commits, and each of these changes should have an associated commit message that describes why the change was made. When you make a commit message via Git Bash, you’re actually only adding a title to your commit message. You’ll need to manually input the reasoning behind the change from the editor on GitHub.

After going through my old commits, I realized that I might have been too lazy to actually write a commit message. But actually no, it's not due to laziness. It's because I don't really know what a good commit message should look like, the format and the content. To edit your commit message, when you’re outside the editor mode, you can use the following code, and then follow the instructions to edit your message:

$ git commit --amend

5. Find Out Which Directory You’re Really In

This might seem like a super simple task, yet I didn’t know how to do this properly. Most of the times I’m just guessing that I’m in the C: directory inside a folder when I’m working on a cloned repo, but apparently there is a way to find that out for sure. Running ‘pwd’ on your bash will return the full path of your current working directory. Never get lost again.

$ pwd
$ /d/folder/subfolder/current-folder

What Worked, What Didn't

It's been years since my first commit, but I still am under the same chaotic aura when I'm coding on GitHub. The last thing I want to do is make a mistake, but if we don't make mistakes we aren't really learning, are we?

These are just some of the very mundane things that I feel I could've done right the first time but didn't. There are a few other Git things that I could add to this list, but maybe for another day. Being the expert procrastinator that I am, I had to wait until the last day of October to start contributing to Hacktoberfest 2018. I've done 5 pull requests today, so hopefully they'll send me my goodie bags this year.

Every coder, new or experienced, must have an opinion about Git. What about you? What are some things you'd like to add to this list?

Be sure to bookmark some of the resources mentioned, for when you need to consult them in the middle of your coding session.

Further readings:

  1. (2018) Getting Started with Git and GitHub. Codecademy.
  2. (2016) Beginner’s Guide to Using Git and GitHub. Code Mentor.
  3. Meghan Nelson. (2015) An Intro to Git and GitHub for Beginners (Tutorial). HubSpot.
  4. Matthew Setter (2015) A Beginner’s Git and GitHub Tutorial. Udemy.
  5. (2018) An Introduction to Open Source. Digital Ocean.

If at first you don't succeed, call it version 1.0.

Questions & Answers

    © 2018 Lovelli Fuad

    Comments

      0 of 8192 characters used
      Post Comment
      • profile image

        Katja 

        3 months ago

        Thanks for updating. I trust you're having fun with the coding. We're looking for people who can help others in our open source projects.

      working

      This website uses cookies

      As a user in the EEA, your approval is needed on a few things. To provide a better website experience, owlcation.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

      For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://owlcation.com/privacy-policy#gdpr

      Show Details
      Necessary
      HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
      LoginThis is necessary to sign in to the HubPages Service.
      Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
      AkismetThis is used to detect comment spam. (Privacy Policy)
      HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
      HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
      Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
      CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
      Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
      Features
      Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
      Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
      Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
      Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
      Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
      VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
      PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
      Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
      MavenThis supports the Maven widget and search functionality. (Privacy Policy)
      Marketing
      Google AdSenseThis is an ad network. (Privacy Policy)
      Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
      Index ExchangeThis is an ad network. (Privacy Policy)
      SovrnThis is an ad network. (Privacy Policy)
      Facebook AdsThis is an ad network. (Privacy Policy)
      Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
      AppNexusThis is an ad network. (Privacy Policy)
      OpenxThis is an ad network. (Privacy Policy)
      Rubicon ProjectThis is an ad network. (Privacy Policy)
      TripleLiftThis is an ad network. (Privacy Policy)
      Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
      Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
      Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
      Statistics
      Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
      ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
      Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)