Using git and github for version backup

Installation

Git is a version control system that I’ve found useful to keep track of changes made to everyday scripts. Install it in ubuntu with:

sudo apt-get install git

Usage

This setup guide taken from here and here

Setup with username and email:

git config --global user.name "Your Name"
git config --global user.email "youremail@domain.com"

Check these details later if you want with:

git config --list

create our workspace environment:

mkdir -p ~/git/testing
cd ~/git/testing

create a test file to use in our repository:

touch file

tell git that you want to use your current directory as a git environment.

git init

add all files and directories to your newly created repository (no output is good output):

git add .

create the message for our initial commit (continue doing this every time you make changes to a file, with an appropriate message):

git commit -m "Initial Commit" -a ## for all files
git commit -m "Initial Commit" file ## for specific file

Check for previous versions:

git log

use the commit number/code in this command if you want to revert to a given version (assuming here that the commit version is abcde):

git checkout abcde file

Usage with github

If you have a github account, pull a repository from there with:

git clone https://github.com/yourname/yourrepo.git

You can commit to you local repository as usual:

git commit -m "change to files" -a ## for all files

if you are happy with the changes, you can push to your github repository with:

git push origin master
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s