kiinlam
10/11/2014 - 2:09 PM

Setting Up Git Workspace

Setting Up Git Workspace

####Restart Git Bash or your terminal

Once you’ve completed the following instructions, you'll need to close and re-open Git Bash (if you are using Windows) or your terminal (if you are using Mac or Linux). Many of the configurations listed here will not take place until you have done this, so if you don’t see your changes taking place right away, this is probably why.

####Downloading necessary files

Later in these instructions, you'll need the two files git-completion.bash and git-prompt.sh. To download them:

  • Visit this page, where you can find git-completion.bash.
  • Right click anywhere on the page and select "Save As..."
  • Save the file to your home directory
  • Rename the file to git-completion.bash using the command line. (Some browsers will name the file git-completion.bash.txt.)
  • Repeat the above steps to save this page as git-prompt.sh in your home directory.

####Creating a .bash_profile

Some of the following configurations will require you to add to a file called .bash_profile, which is used to configure Git Bash if you’re using Windows, or the terminal if you’re using Mac or Linux. (If your terminal is using a different shell than bash, than many of the following instructions will not work. However, bash is the default on both Mac and Ubuntu.) Note: Since this file has a period at the beginning of its name, it is called a hidden file and will not appear in most file system navigators. To create this file:

  • Navigate to your home directory
  • Create a new file named .bash_profile
  • Use ls -a, which shows hidden files, to confirm your file has been created.

####Setting up tab completion

Setting up tab completion allows you to type the first few characters of a Git command, press tab, and have the rest of the command filled in. Having tab completion set up can make working with Git much more efficient.

To set up tab completion:

  • Follow the instructions above in the section "Downloading necessary files" to make sure your home directory contains the file git-completion.bash.
  • Add the line source git-completion.bash to your .bash_profile.

####Configuring your name and email

When you used git log earlier, you saw that Git listed the author of each commit. In order to do this, Git needs to know your name and email address. In fact, Git will not allow you to commit before you’ve given it this information. To do so:

  • Run git config --global user.name "Your name"
  • Run git config --global user.email "youremail@domain.com"

Fill in your own name and email address where indicated.

####Set up a default editor

Sometimes Git will automatically open a text editor. For example, if you make a commit without specifying a commit message, Git will open a text editor and allow you to use it to write the commit message. You’ll want this editor to be one you like. To configure which editor Git will open:

  • Make sure you can open your editor from the command line.
  • Run the command git config --global core.editor, followed by the command you run to start your editor.

For example, if you use Sublime, you would run git config --global core.editor "subl -n -w".

####Restart Git Bash or your terminal

Don’t forget to do this, or some of your changes won’t take effect.