git config --global merge.tool vimdiff
Archive for the ‘Git’ Category
For some reason I haven’t been able to find any good
git-tag examples online. The best example I can find anywhere is on page 43 of Jon Loeliger’s Version Control with Git, and even that example is arguably incomplete. Here’s the example from the book:
$ git tag -m"Tag version 1.0" V1.0 3ede462
Now you have a tag. But if you do a push and then, on a different clone, do a pull and run
git tag, the tag won’t show up. Why not? You need to push it, but the book doesn’t tell you how (at least not right there in the same example). Here’s what you need to run to push the tag:
$ git push --tags Counting objects: 1, done. Writing objects: 100% (1/1), 189 bytes, done. Total 1 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (1/1), done. To /var/git/mcif.git/ * [new tag] V1.0 -> V1.0
Now we see something happen.
It also may be good to know that you can run
git-show V1.0 to see details about this tag.
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:
- You have Git installed on both your local and remote machines
- Your username is “bob”
- Your remote host is example.com
- You have shell access to your remote host
First you need to create a repository on your remote machine. We’re going to do this in
$ 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://email@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://firstname.lastname@example.org/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
$ 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: