Andre's Blog

Andre's Technical Blog About Using Git


20160424 About This Technical Blog
Git Idea And Structure
How To Add Files
How To Commit Files
How To Get The History Of Commits
How To Create A Branch
How To Link A Local Repository With A Remote Server
How To Push Local Commits to The Remote Server
How To Update A Local Branch From The Remote Server
How To Merge A Branch X Into Y
How To Reset Commit/s
20160717 How To Create A Repository On A Synology Station
20160717 How To List The Git config
20160717 How To Auto Rebase Before Pull

20160424 About This Technical Blog

To know why I write a blog about using Git, please read my blog post

Git Idea And Structure

Git is a version control system.

You have a local git server where you add local files to become git controlled.

Revisions of git controlled files are called commits.

To seperate changes of the same files in different revisions you create branches.

To store changes on a remote git server, the local git branch is updated to its corresponding branch on the remote git server.

Changes from the remote server are pulled, local changes from the local to the remote server are pushed.

How To Add Files

Adding a file :

git add filename

Adding all files recursive down from the current directory :

git add .

How To Commit Files

git commit -m "commit comment"

How To Get The History Of Commits

git log

How To Create A Branch

git checkout -b branchname
git update -u origin branchname

How To Push Local Commits to The Remote Server

git push

How To Update A Local Branch From The Remote Server

git pull

How To Merge A Branch X into Y

git checkout X
git pull
git checkout Y
git merge X
git push

How To Reset Commit/s

To see the commit history :

git log

To set the commit history 1 step back without changing the file content :

git reset HEAD~1

This works for every number of steps, e.g. reset the last 3 steps :

git reset HEAD~3

To reset the file content of a file after a commit has been reset :

git checkout path/filename

To reset the commit history and reset the file content 1 step back :

git reset --hard HEAD~1

20160717 How To Create A Repository On A Synology Station

Working with Git without a remote server is only half of the fun.

This is how I have set up my repository on my Synology station :

$ ssh 192.168.2.20
$ mkdir gitrepo
$ cd gitrepo
$ mkdir blog.git
$ cd blog.git
$ git init --bare --shared
$ chmod -R o+w blog.git

then I was able to clone it on my netbook :

$ git clone ssh://amos@192.168.2.20/volume1/homes/amos/gitrepo/blog.git

and I have configured a push strategy :

$ git config --global push.default matching

20160717 How To List The Git config

git config --list

20160717 How To Auto Rebase Before Pull

There are two ways of how to pull changes from the server :

  1. rebase the pulled changes and add your changes on top
  2. merge the pulled changes on top of your changes

I prefer the first way.

The blog of Steven Harman explains it very good.

To configure the pull rebase to do it automatically, you have to :

git config --global pull.rebase true

Select where to go ...


The Blog
My Technical Blogs
Projects
Blogs Of Friends
RSS
CV/About
Me