With knowledge of only a few commands, it's easy to get up and running with Git. Although future you will thank current you if you got a more in depth working knowledge of this brilliant software.
Going deep not only makes your life easier, it gives you super powers and helps you develop the programming habits future you will look back and smile about.
First some fundamentals.
Git is a version control system for tracking changes in your files. If you have files that you send out which are likely to change, Git can help you track these. It's hard enough tracking these files on your own, but think of what happens when you are part of a team with files that change regularly. Think of what happens when you make changes to files that are also subject to change! It will be difficult to do without a version control system and more importantly a version control philosophy.
There are multiple version control systems in the wild, each with a different process flow and philosophy. What makes Git different is rather than making a copy of the entire repository when a new version is created, it just tracks the changes. This way the size of the entire repository is minimized as it just holds the delta between versions.
One of the great advantages of git is that you can store your files in an online repository. Not only is this a great way of transferring files over the net but it acts as a backup to your work. With a few git hacks that are discussed later, it can be a great aid to your workflow. Helping with things like trial and error and experimentation. Letting you erase history if things go wrong.
Github is an online repository which promotes opensource software by not charging for publicly available software projects. They also have the option to store your private repositories for a fee which makes it a great solution to keep all your software in one place. In your local folder which contains software, you initialize a repository and then link it to the online repository which is called a remote. You tell Git what files you want to track and commit any changes to these files to the online repository. For instance, if you create an online repository called
test-repo, the URL for this is likely to be
http://github.com/yourusernamehere/test-repo.git, your username being
In the directory you want to track:
git init git remote add origin https://github.com/user/repo.git
Either all or specific files can be added to the repository. This helps you sort the important files form the clutter. You need to be in the directory when executing these commands.
Add all files to the repository. Add only files with doc extension.
git add . git add \*.doc
There are shortcuts to these commands
git update -u git add -A
Added files can be committed to the local version of git to be subsequently uploaded to Github. You can also add a descriptive message here in order to track back to a particular version.
git commit -m "message about commit"
Pushing pushes all the files you have committed in your local directory into github.
git push origin master
You can think of a git branch as a branch from a tree. A branch creates a new version of the repository this means that any changes made from the point of creating and moving to the branch will only apply to that branch. The
checkout command moves you to a different branch or creates a new branch.
git branch git checkout -b branchname
Cloning a repository
One of the advantages of an online open source repository is that there is a multitude of software projects available to you. You can download and have access to some of the best software projects in the world with a single command. Where
repo is the name of the software project.
git clone https://github.com/user/repo.git
HEAD is a pointer to the last commit in a branch. This was before you made any changes since your last commit. A quick way to go back to the last commit is to use the
reset. The great thing about this command is that you can go back to any previous commit you have done in the repository.
git reset --hard HEAD git reset --hard <some commit>
git status command shows you the changes since you last commit. It is worth running this before committing changes to see if this is expected. The
git diff command shows you the actual text lines in your repository of the changes.
You can set the global user name and email address. This way, git wont ask you for these every time you need to log in to upload your code to remote.
Financial Analyst delivering comprehensive insight and modelling solutions in an array of business settings. Commercially aware and multiskilled with a proven track record of implementing measurable results due to business savvy and innovative solution design. I have worked with a variety of organisations from FTSE100 companies to public sector organisations both in the UK and abroad.