git

Git Logo

Getting Started With Git

30th May 2021 - 21 minutes read time

I have been using Git for a number of years and I can remember feeling quite daunted at the complexity of some of the commands I saw on the internet. When I started using Git on a daily basis I soon realised that the basics were quite simple and the complexity only lay further down the road with commands like cherry-pick or rebase.

Whilst Git does sometimes make me scratch my head, it is never as bad as the days of SVN where I would have a notepad of 'fix' commands that I would copy and paste into my terminal to solve random problems. I usually didn't even know what the problems were, just that this command fixed things so I could continue on and not lose work.

Git Logo

Git: Compare Differences Between Branches

7th March 2021 - 4 minutes read time

The git diff command will allow you to view the differences in your workspace. This can be used in a number of ways to look at the differences in a file, in a branch or between two branches.

For example, you can view the differences in your current workspace by just running git diff on its own. By supplying a file you can look at the differences in just that file.

To compare the difference between one branch and another you use '..' to separate the branch names. For example, to look at the differences between the head of the 'main' branch and the head of a feature branch use this syntax.

git diff main..feature_branch

This can often be quite noisy, especially on large projects, so to check just one directory between two branches you can add the directory path to the command.

PHP Logo

Committing The Composer Vendor Directory

13th September 2020 - 21 minutes read time
When installing composer dependencies those dependencies are downloaded and stored in the 'vendor' directory. There are options available to install this into a different location than the composer.json file, but it's generally found in the same directory. The vendor directory contains quite a bit of code, which is especially the case if your project contains quite a lot of dependencies. More often than not though, this directory will not contain any code that you have actually written. It will contain the necessary third party libraries that allow your code to work correctly.
Git Logo

Tidying Up A Git Repo

4th April 2020 - 5 minutes read time

Creating branches in git basically free and is easy to do. This has lead to the development of techniques like git flow and other branch related work streams, which are now commonplace in development.

If you have a project being worked on by many developers you can get into the situation where there are many branches in the project. Some will be merged, some will be worked on currently and some more will be branches that were worked on, but never finished (for one reason or another). This can lead to some confusion over what branches are being worked on, especially if you want an oversight on the current health of the project.

Git Logo

Force Update Of Git Repository

22nd January 2013 - 2 minutes read time

If you have changed or updated a git repository and want to throw away your changes then a good way of forcing the latest changes to run a combination of two commands. The first command is git fetch --all, which tells git to download the latest updates from the remote without trying to merge or rebase anything. This is followed by git reset --hard origin/master where git resets the master branch (assuming you were on the master branch) to become the version of the master branch you just fetched. Here is the two commands in full:

  1. git fetch --all
  2. git reset --hard origin/master

There are a few reasons why you might want to do this but should remember that any changes you have made to files in the repository will be binned in favour of the latest version.

Git Logo

Find The Number Of Commits In A Git Repository

25th June 2012 - 1 minute read time

Use the following command to find out how many commits there have been in a git repository. Not really useful in itself, but an interesting figure to see how active a project has been over it's lifetime.

git log --oneline --all | wc -l

The following git log flags are in use here:

--oneline - Removes some of the information from the log entries and displays each on a single line.

--all - Shows all commits across all branches.

The -l (lower case L) flag is supplied to the wc command so that it counts the number of lines in the given input.

Git Logo

How To Ignore Mode Changes In Git

25th June 2012 - 2 minutes read time

Git will track changes to files and directories, including any changes to permissions done via chmod. In most development environments I tend to have a different set of permissions to those on the live site so I am usually not interested in tracking permissions changes. To prevent git from looking at the difference between the permissions of a file you need to set the core.filemode configuration option to false.

git config core.filemode false

Here is the entry from the git-config(1) manual page.