Showing posts with label Git Bash. Show all posts
Showing posts with label Git Bash. Show all posts

Sunday, December 7, 2014

Review commit history using Git log

The $git log command is used to review the commits performed on a repository/branch. The command lists out the various commits performed with details of the date when the commit was done and the user who performed the commit.

The following is the syntax for the log command.

Get status of working folder using git status

The git status command is used to inspect the status of the local working folder and the stage/index, this gives the list of files which are added/modified in the local copy but not reflected in the stage/index.

The following images shows the output of git status command in the following 3 situations.

List out all the branches in the current repository


In the previous post we saw on how to switch to a specific branch using the checkout command, at times we might have more branches in a repository which we cannot remember always, the $git branch command is used to list out all the branches in the current repository.
The following command lists all the branches in the repository.

Checkout a branch using Git Bash

The checkout command is used to switch to a specific branch, also the checkout command gets the latest changes from the specified branch and updates them to the local working folder. Before using the checkout command to switch to a branch, the specific branch should be created using the git branch command.  

The checkout command can be used with the –b switch to create a new branch and switch to that branch in a single command.

Pull changes from a remote repository using Git Bash

The pull command is used to get the latest from the remote repository to the local working copy, the pull command pulls changes committed and pushed by the other users to the local working copy. It is advisable to pull changes before starting to make changes in the local copy this will help to avoid merging changes made by other users later when we want to push our changes to the remote repository.

Use the following steps to pull changes from the remote repository to the local working folder.

Sunday, November 30, 2014

Push changes to a remote repository using Git Bash

Push is the stage where the changes from the local repository get moved to the remote repository, once the changes are committed to the local repository push command will push the changes to the remote repository.

Changes in local working copy -> Stage -> Commit -> Push changes to remote repository

The following steps push the changes from the local repository to the remote repository using Git Bash commands

Committing changes to a local repository using Git Bash

Once the local changes in the working copy are staged/indexed, the next step is to commit the changes to the local repository this will move the changes from staging to the local repository.

Working Copy changes -> Stage/Index -> Commit to Local Repository -> Push to Remote Repository

Use the following steps to commit the changes from stage/index to the local repository

Staging changes using Git Bash

Staging changes using Git Bash 

Once the changes are done in the local working copy, they need to be staged/indexed, this will move the changes to the staging area, from here the changes should be committed to the local repository, and finally be pushed to the remote repository for other users to use the changes. 

Working copy -> Staging -> Commit to Local Repository -> Push to Remote Repository
Use the following steps to stage changes using Git Bash

Cloning a Remote Repository using Git Bash

Cloning a Remote Repository using Git Bash

The clone command can be used to cone a copy of the existing remote repository, alternatively you can also create a new repository all together using the “$ git init” command.

In this post we shall cone an existing repository, which resides in a remote machine. In my case the remote repository is hosted in BitBucket, you can clone any remote repository from the web like BitBucket, GitHub etc or from a local machine in the network.


Use the following steps to clone a remote repository using Git Bash

Getting started with Git Bash

Getting started with Git Bash

Before starting with Git Bash, make sure that you download and install the latest version of Git for Windows.

You can get the installation files from the below URL
http://msysgit.github.io/

Once installed, you can see Git UI & Git Bash added to your programs list as follows.

What is Git Bash?

What is Git Bash?

Git Bash is a command line interface through which we can interact with the Git version control system. Git Bash supports commands like cd which can be used to explore physical file locations in the local system and commands to operate on the underlying Git version control system.

Git Bash, is part of the Git for Windows installation, more details on Git for Windows can be found from the following site.