What is Git?
Git is a tool that allows anyone to control and manage each version of a file/folder on their computer. It also allows for collaboration with others working on the same project - and easy sharing of any project.
Git is not Github
While GitHub is great to use alongside Git, Git has a very different history. Git was originally concieved by (amonsgt others) Linus Torvalds - more famously known for creating the Linux kernel. Back then, Git was constructed in order to facilitate the open soruce development of Linux OS.
GitHub emerged later as a derivative of Git. Today, Git paired with GitHub allows you to display your work online in repositories that serves as an online backup that you can access from any computer.
GitHub also allows for cooperation on everything from a school-project to a complete web-development framework - like Ruby on Rails.
Installation
Before we get into the essential Git commands, the software needs to be installed. I use Git with GitKraken.
Arch Linux Install
sudo pacman -S git
yaourt gitkraken
Guide on how to set up yaourt (AUR-package manager) coming
Install on Ubuntu/OSX etc
Download [latest Git source package](https://git-scm.com/)
Download [latest GitKraken](https://www.gitkraken.com/download)
I primarily use GitKraken to track previous changes and browse local repositories.
Getting started with Git
Having succesfully installed Git, you’re ready to go ahead and set up using the terminal. Configure your credentials - these should not differ from you GitHub profile information, if you already have one.
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
# You can set Git to recognize your preferred editor
# Git takes your systems default editor
git config --global core.editor vim
If you want to, you can check that you entered the right information by listing the configurations:
git config --list
By now, you’re ready to go ahead and initialize a local repository/repo. You do this by setting you current directory to a folder, you would like to keep track of:
cd ~/yourdir/yourfolder
git init
To check that everything is working as intended, go ahead and add a line to any of the documents in yourfolder. From there, you can stage (add) and commit your files.
git add .
git commit -m 'youfirstcommit-ment/'
Now, you can open GitKraken and press Ctrl+o. This will open a Repo - find the repository, you just created and there you go - now you can track changes.
It is important to note, that Git will only track your changes as long as you stage and commit your files.
Syncing with Github
Normally, when pushing your repo to Github, you create a README.md file:
cd ~/yourdir/yourfolder
touch README.md
You can write whatever you find appropriate in this markdown document. This will be displayed on your repo’s frontpage on Github and will serve as an introduction to your project.
On Githubs website, you can easliy “Import Repository”, which will import your local repo to Githubs servers and thus be accessible from anywhere with an internet connection.
If, however, you wish to do this from a terminal, you can do the following. Assuming, that you’ve created a project on the master branch - and that you want to keep it that way:
cd ~/yourdir/yourfolder
git checkout -b master
git remote add origin http://github.com/yourprofile/yourrepo.git
git push -u origin <branch>
# Or..
git push --set-upstream origin <branch>
# Or..
git push
That’s pretty much how i use Git to keep track and do VC on my local machine.
What about "Social Coding"?
The social part of Github becomes relevant when doing projects with groups of other individuals.
You can easily fork, clone or branch out of existing repos, that other users have built.
If, for example, you discover an awesome project that someone has on Github, and you want to contribute or just use some of the code for your own purposes, you can clone it from the URI/URL provided when clicking the Clone or download button on the relevant Github page.
These are the basics, that you’ll need to know in order to get started with Git and Github on your PC. You can expand your knowledge of branches and more advanced features on the various blogs covering these topics.