Git Setup

Download and Install Git

  1. Download the installer for Git from http://git-scm.com/download, or another link for Windows https://git-for-windows.github.io, it should automatically download the latest version.

  2. After downloading, run the installer, accept the defaults except when asked about adjusting your PATH environment. Make sure you select the "Run Git from the Windows Command Prompt" option.

  3. Once the installer is finished, confirm the correct version installed successfully by running the following command: git --version.

Configure Git

Set Git Proxy

Git does not seem to use the network proxy environment variables so you need to set the proxy variables within the Git config. This assumes you're using CNTLM on the default port

git config --global http.proxy http://localhost:3128
git config --global https.proxy http://localhost:3128

Set Your Git Name and Email Address

git config --global user.name "<<My Name>>"
git config --global user.email "<<[email protected]>>"

Use the HTTPS Protocol Instead of the GIT Protocol

By default, NPM attempts to download dependencies from GitHub via the git:// protocol over port 9418. Unfortunately, some firewalls may block that port. To get around this, we need to tell Git to use the https:// protocol instead.

git config --global url.https://github.com/.insteadOf git://github.com/

Handle Self-Signed Certificates

git config --global http.sslVerify false

Handle Long File Names

git config --system core.longpaths true
error: could not lock config file C:\Program Files (x86)\Git\mingw32/etc/gitconfig: Permission denied
git config --global core.longpaths true
git checkout -f HEAD

Handle Unix File Ends on Windows

git config --global core.autocrlf true

Git Bash SSH Keys

  1. Start up Git Bash: Start -> All Programs -> Git -> Git Bash

  2. On the command prompt, type in the following command substituting with the email you used to sign up for GitHub. When it asks you for the file, just hit Enter. Please note that you should definitely enter a passphrase; when you type, nothing will show up. This is normal, don't worry about it.

    ssh-keygen -t rsa -C "[email protected]"
    
  3. Use Notepad to open up the .ssh/id_rsa.pub file you just generated and copy all of the contents of that file.

  4. Link Your SSH key with GitHub Open up your GitHub profile which is where you'll paste the public key you just copied from the previous step. Click "Add Key" after you've pasted the key into the box.

Setup Repository

Option1: Initializing a Repository in an Existing Directory

If you’re starting to track an existing project in Git, you need to go to the project’s directory.

$ cd /home/user/my_repository
$ git init

This creates a new subdirectory named .git that contains all of your necessary repository files – a Git repository skeleton. At this point, nothing in your project is tracked yet. If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a git commit

Option2: Cloning an Existing Repository

If you want to get a copy of an existing Git repository –the command you need is git clone. Instead of getting just a working copy, Git receives a full copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down by default. In fact, if your server disk gets corrupted, you can often use nearly any of the clones on any client to set the server back to the state it was in when it was cloned (you may lose some server-side hooks and such, but all the versioned data would be there).

For example, if you want to clone the Git linkable library called kfang2, you can do:

$ git clone https://github.com/kaifang/kai-book.git
$ git clone https://[email protected]/scm/xyz/HelloWorld.git

That creates a directory named “kai-book”, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new “kai-book” directory, you’ll see the project files in there, ready to be worked on or used.

If you want to clone the repository into a directory named something other than “kai-book”, you can specify that as the next command-line option:

$ git clone https://github.com/kaifang/kai-book myProject

Git has a number of different transfer protocols you can use. The previous example uses the https:// protocol, but you may also see git:// or user@server:path/to/repo.git, which uses the SSH transfer protocol.

results matching ""

    No results matching ""