ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Git Essentials Part 2

Updated on March 23, 2015

3 Type of Git Configuration

1. System Level Configuration

  • The larges configuration that apply every user of a computer
  • Unix: /etc/gitconfig
  • Windows: Program Files\Git\etc\gitconfig
  • git config --system

2. User Level Configuration

  • Apply for a single user on a computer
  • Unix: ~/.gitconfig
  • Windows: $HOME\.gitconfig
  • git config --global

3. Project by Project basis

  • Apply only to a project
  • My_project/.git/config
  • git config

Setting Username and Email Address

The information (username and email address) is used by Git for each commit,

use command git config --global user.name "yourname" and git config --global user.email "youremail"

Listing Git Settings

To verify your Git settings, use the command git config --list to show all settings we feed on git

Directory Listing and Opening File

To show the list of directories, use the command ls -la

As yo can see the .gitconfig on the list directories, there are a number of ways to open a file but we will used the command cat .gitconfig

Other Commands

Visit the link http://www.tutorialspoint.com/git/git_environment.htm to find more commands.

Initializing a Repository

After the installation and configuration of Git, the next step is to initialized a project that will tell Git to keep track of changes on the project.

Steps to Initialized a Project

1. First thing to do is to decide where the project folder will be put., in this example we will put the project folder on the D:\Program\GitProjects\FirstGitProject

2. To access the directory of the project folder on Git Bash, used the command cd to go back to main directory, cd folder\

From the figure above, we used the cd D:/Program/GitPojects/FirstGitProject/ to go inside the folder of our project.

3. Inside the folder, we will initialized the FirstGitProject by using the command git init, it will make the FirstGitProjects as Home Based or the Repository to track all changes made

Note: Outside of the folder is not concerned.

Notice that it will return "Initialized empty Git repository in FolderDirectory/.git", the .git is used for storing and tracking.

4. To check if .git is in the FirstGitProject, use the command ls -la

5. Now we will check what's inside .git, use the command ls -la .git

Performing Commit

1. To start with, we will create a new file on any text editor like notepad and saved it to our repository.

2. Now we will tell Git that we will make changes by using the command git add . (add every changes made on the directory to the staging index) or git add file_name (add the specified file on the staging index)

3. Next is to commit all changes on the repository by using the command git commit -m "Initial Commit", the commit means to save all added files on the repository and -m means the commit message

Notice that it return the file we created (FirstFile.txt) was inserted in our repository and that is how the Git track changes on our repository.

Commit Message Best Practices

  • Short single-line summary (less than 50 characters)
  • Optionally followed by blank line and a more complete description
  • Keep each line to less than 72 characters
  • Write commit messages in present tense, not past tense
    • "fix bug" or "fixes bug" not "fixed bug"
  • Bullet point are usually asterisk or hyphens
  • Can add "ticket tracking number" from bugs or support request
  • Can develop shorthand for your organization
    • "[css, js]"
    • "bugfix:"
    • "#38405 - "
  • Be clear and descriptive
    • Bad: "Fix typo"
    • Good: "Add missing > in project section of HTML"
    • Bad : "Update login code"
    • Good: "Change user authentication to use blowfish"
    • Bad: "Updates member report, we should discuss if this right next week"

Example:

T23094 - Fixed bug in admin logout

When an admin logged out of the admin area, they could not log in to the members area because their session[:user_id] was still set to the admin ID. This pastch fixed th bug by setting session[:user_id] to nil when any user logs out of any area.

View Commit Log

Since you know how to commit and write a good commit message, let's take a look were those commit message show up by using the command git log

You'll notice that there is only one log, If there are two or many commit it will show one after another.

The commit cbd8e5….. is the commit id or identifier, each commit has it own unique id. The author who committed file, the date committed and the Commit Message.

Other useful log command

  1. The command git log -n 1 is used to limit the number of committees to be viewed, the -n 1(any number) means number of committees.
  2. The command git log --since=yyyy-MM-dd is used to specify the date range since the commit is done.
  3. The command git log --until=yyyy-MM-dd is used to specify the date range since the commit is done.
  4. The command git log --author="authorname" is used to view commits by the user
  5. The command git log --grep="SomeWord" is used to search if a commit contains the global regular expression word.

Git Rating

Cast your vote for Rate Git

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.

    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, hubpages.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://hubpages.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)