ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Software

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