A Technology Blog About Code Development, Architecture, Operating System, Hardware, Tips and Tutorials for Developers.

Tuesday, July 17, 2012

GIT - Setup

8:03:00 PM Posted by Satish Kumar , , , No comments

Git allows you to store global settings in a .gitconfig file. This file is located in the user home directory. As mentioned before Git stores the committer and author in each commit. This and additional information can be stored in the global settings.

The following will configure Git so that a certain user and email address is used, enable color coding and tell Git to ignore certain files.

User Configuration

Configure your user and email for Git via the following command.

# Configure the user which will be used by git
# Of course you should use your name
git config --global user.name "Example Surname"
# Same for the email address
git config --global user.email "your.email@gmail.com"
# Set default so that all changes are always pushed to the repository
git config --global push.default "matching" 

To query your Git settings, execute the following command:

git config --list

Color Highlighting


The following will enable some highlighting for the console.

git config --global color.status auto
git config --global color.branch auto 

Ignore certain files


Git can be configured to ignore certain files and directories. This is configured via the .gitignore file. This file can be in any directory and can contain pattern for files. For example, you can tell Git to ignore the bin directory via the following .gitignore file in the main directory.

bin 


Git also offers the global setting core.excludesfile to specify global excludes.

You can also setup a global .gitignore file valid for all Git repositories.

# Create a ~/.gitignore in your user directory
cd ~/
touch .gitignore

# Exclude bin and .metadata directories
echo "bin" > .gitignore
echo ".metadata" >> .gitignore

# Configure Git to use this file
# as global .gitignore

git config --global core.excludesfile ~/.gitignore 


Tracking empty directories with .gitkeep

Git will ignore empty directories, e.g. do not put them under version control. If you want to track such directories, is it convention to put files called ".gitkeep" in these directories. The file could be called anything; Git assigns no special significance to this name. As the directory now contains a file, Git will include it into its version control mechanism.

0 comments:

Post a Comment