To turn colors on in Git, just run the following command:
$ git config --global color.ui "auto"
To turn colors on in Git, just run the following command:
$ git config --global color.ui "auto"
Creating a remote repository with Git is really easy but all the tutorials I’ve seen out there make it harder than it has to be. Here are some simpler instructions.
For the purposes of this example, we’re assuming:
First you need to create a repository on your remote machine. We’re going to do this in /home/bob/my-project.
$ cd /home/bob $ mkdir my-project $ cd my-project/ $ git init Initialized empty Git repository in /home/jason/my-project/.git/
Your Git repository now exists. Right now it’s empty—let’s add one file so we have something to check for when we clone the repository to our local machine.
$ touch file1 $ git status # On branch master # # Initial commit # # Untracked files: # (use "git add..." to include in what will be committed) # # file1 nothing added to commit but untracked files present (use "git add" to track) $ git add file1 $ git commit -m "Initial commit." [master (root-commit) 04df0da] Initial commit. 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 file1
Now we have one file, file1, in our Git repository.
Although we now have a perfectly good repository, that’s not actually the one we’re going to clone from our local machine. We’re going to create what’s called a bare repository for that. According to Jon Loeliger’s excellent Version Control with Git: Powerful Tools and Techniques for Collaborative Software Development, “If you set up a repository into which developers push changes, it should be bare.” That’s what we want, so that’s what we’ll do.
$ mkdir /var/git $ cd /var/git $ git clone --bare /home/jason/my-project/ my-project.git Initialized empty Git repository in /var/git/my-project.git/
Note: There’s nothing special about the directory /var/git. We could have chosen anything and it would have worked just as well.
Now we have a bare repository in /var/git/myproject.git. This is the repository from which we’ll clone our local repository using the git clone command:
$ git clone ssh://bob@example.com/var/git/my-project.git my-project Initialized empty Git repository in /var/www/my-project/.git/ remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done.
If everything worked correctly, you should have gotten the same results I did. Let’s take a look at the repository to see with our own eyes that it came across okay:
$ cd my-project/ $ git status # On branch master nothing to commit (working directory clean) $ ls file1
There’s our old friend file1. Now that we’ve cloned the repository to our local machine, can we push changes back to the remote repository?
$ touch file2 $ git add file2 $ git commit -m "Added file2." Created commit fa20318: Added file2. 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 file2 $ git push origin master Counting objects: 3, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 239 bytes, done. Total 2 (delta 0), reused 0 (delta 0) To ssh://bob@example.com/var/git/my-project.git 04df0da..fa20318 master -> master
That seemed to go well. Let’s go back to that first repository we created—not the bare one but the very first one&dmash;and see if these changes come through in a git pull.
$ cd /home/bob/my-project/ $ git pull /var/git/my-project.git/ remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 2 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (2/2), done. From /var/git/my-project * branch HEAD -> FETCH_HEAD Updating 04df0da..fa20318 Fast forward 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 file2 $ ls file1 file2
There you have it. You’re done!
And by the way, check out this book. It really is great: