Git for Designers
GIT is a version control system that is getting a lot of good reviews lately, and we’ve started to use. I thought I’d relate a methodology that we’ve arrived at in very simple terms, that even a designer can understand.
We all have GitHub repositories, and we are using local branches to work on our respective development tasks. So, the dilemma is to how to share work in our branches and repositories with each other without having to commit to the master repository.
An answer comes in the form of remote branches and pull requests.
The theory goes like this…
- Make a copy of the latest version of the code, on one’s own repository, get a local copy of that code, and develop to your hearts content – including creating branches for different aspects of the work.
- Periodically check the original to make sure one’s repos and local code is up to date.
- Commit changes to local and own repositories – including any branches that you think you might want to share.
- Get those changes into the master repository.
Ok, so let’s make it happen.
First thing to do is make a fork of the original repository, by pressing the fork option on the github home page.
This creates a repository that you can then get onto your machine with the git clone command.
git clone email@example.com:bossuser/forkedrepos.git
CD in to the folder that has created
Have a little check of all your branches with
git branch -a
So, the next thing we need to do is track the remote branch so that we get any changes from the original repos that we forked from.
git remote add branchname firstname.lastname@example.org:user/originalrepos.git
branchname is the name you give to the tracking branch. It doesn’t show up when you run
git branch -a yet, but some lines have been added to your config – open up .git/config and you will see that the branchname points to the original repos.
url = email@example.com:user/originalrepos.git
fetch = +refs/heads/*:refs/remotes/practiceb/*
So now, I’d like to get something into this branch to check it’s tracking correctly. I can do that by running
git fetch branchname
Which gets some files from repos.So, this time when you run
git branch -a
Your remote branch called branchname appears in your list or branches.
So now you are tracking this branch, but According to the GIT Manual you cannot checkout a remote tracking branch. Instead you need to create a local branch, which you do with the following command.
git checkout --track -b newlocalbranchname branchname/master
Just to be sure have a look with
git branch -a and you should see the new branch with an asterix, indicating the branch you are currently on.
So, if you remember the theory, we’ve now got a local branch with the changes from the original repository, and a local master branch with changes from our forked repos. This gives us the mechanism to get any changes from the original repos.
git pull whilst in our newlocalbranch. This fetches and merges. We can then switch to our master branch with
git checkout master from where we run
git merge newlocalbranch pulling the changes over.
The next bit of the theory was to put our changes up. That is pretty easy – after our minutes of productive work you decide you’re happy with your changes.
git commit -a
git push to get it onto your github repository
The final piece of the jigsaw is to get your changes into the original repository. You can do this by sending a pull request to the admin for the repository. The button is on the github homepage of the repository.
And there you have it.