This is a quick tutorial on how to use git. Git is a software for tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during software development. Its goals include speed, data integrity, and support for distributed, non-linear workflows.
Step 1: Install Git
Install Git on your OS. Instructions can be found here https://git-scm.com/downloads
Step 2: Create local git repository
git init
Step 3: Add files to your project
I’ve added a simple html and a style.css
-rw-r--r--. 1 root root 0 May 18 13:29 index.html
-rw-r--r--. 1 root root 0 May 18 13:29 style.css
Step 4: Config user and email
Before committing files you have to setup email and user first.
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
# get config
git config --global --list
Step 5: Add files
Before actually adding files you can check git status with command to see pending changes:
# print status
git status
# add specific files
git add index.html styles.css
# add all files in current directory
git add .
Step 6: Commit changes
Commit pending changes with a comment
# commit
git commit -m "add two files"
# print log
git log
Step 7: Create new branch
# print all branches and current branch
git branch
# create new branch
git branch my-new-branch
# switch to new branch
git checkout my-new-branch
Step 8: Merge branch
Make some changes in the new branch and then merge it to master branch
# switch back to master branch
git checkout master
# merge changes
git merge my-new-branch
Step 9: Rollback to an early commit
Get your commit id hash and checkout
# list log and get commit id
git log
# rollback to commit a6f93315ec9e1bb4151689e6c0be810072cd93c1
git checkout a6f93315ec9e1bb4151689e6c0be810072cd93c1
# get back to latest change
git checkout master






