GIT getting started on Linux


If You start using GIT with a GUI, and did not study concept of GIT, most likely You using it wrong! Or if You trying to use it as some other software that You already know, most likely wrong idea to!
I tried a few git GUI's, and if You don know the idea how it should work, its definitely not obvious from the GUI! In Other cases GUI is just a CRAP and it's impossible to use it.

     Why GIT?   Tech Talk: Linus Torvalds on git (Youtube Video)

     GIT workflow...  Introduction to Git with Scott Chacon (Youtube Video)

Basic git config:

$ git config --global user.name "User"

$ git config --global user.email "user@mail.com"

$ git config --global color.diff auto

$ git config --global color.status auto

$ git config --global color.branch auto

$ git config --global core.editor "nano"

Global settings stored in file:

$ cat ~/.gitconfig

Adding a project:

Enter project dir and

$ git init

$ git status

Adding & Commiting:

$ git add file.c

$ git commit

Commit message list:

$ git log

Add all files to staging area

$ git add .

Helpful note for a people, who is not a vim fan's
To exit vim

Doing backup to a flash drive:

Enter dir where git remote will be created

$ git init --bare

Now back to project dir:

$ git remote add {nameOfTheRemote} {PathToRemote}
$ git remote add {nameOfTheRemote} \

Push to empty remote:

$ git push {NameOfTheRemote} {BanchName}

Push all branches to remote:

$ git push {NameOfTheRemote} -a

List remotes:

$ git remote -v

Get a source copy from remote

$git clone {PathToRemote}

List your available branches:

$ git branch

Create a new branch:

$ git branch {newBranchName}

$ git branch testing

Switch to a branch:

$ git checkout testing

Merge testing to master, make sure you are on a master branch:

$git branch



$ git merge testing

Delete a branch:

$ git branch -d {branchName}

$ git branch -d testing

Delete remote branch

$git push origin --delete {branchName}

Difference between HEAD and the index;
what would be committed if you "commit" now.

$ git diff 

A brief per-file summary of the above.

$ git status

Get info about your local folder content versus remote content

$ git remote show {nameOfTheRemote}

Check all branches:

$ git branch -a

$ git branch -r

Get updated from remote

$ git fetch

Show git branch chart:

$ git log --oneline --graph --all --decorate

Make "com" alias for "commit":

$ git config alias.com commit

Switch to your other branch:

$git checkout {branchName}

Show log with file'e change summary:

$git log --stat

Compare branches. What is in branch called "master" that is not in the "bug_fix":

$git log master ^bug_fix

Usually binary files excluded from source. With Git it can be done by make a file ".gitignore" in the project directory:

Content of gitignore
exclude file by extension:
exclude all folders named “Debug” in the soure tree:
exclude single folder:


If you want to create a patch file via "git diff" that can be applied using "patch -p0 < patchfile" use the following command:

$ git diff --no-prefix > patchfile

then apply the patch:

$ patch -p0 < patchfile

If you have an existing "git diff" patch file that was created without the "--no-prefix" option, you can apply that patch via:

$ patch -p1 < patchfile

this will ignore the default a/ b/ source prefixes.
To make a complete patch not only modified files bud new files to.
You have to staged all files for patch, you can unstage after you create a patch, don't have to commit!

$ git diff --no-prefix --staged > patchfile

Replace local branch "master" to the remote branch "master"

$ git checkout origin/master
$ git branch -d master
$ git checkout -b master

Visualize git repo with web gui

$ git instaweb

Git on server

$ cd gitproject.git
$ mv hooks/post-update.sample hooks/post-update
$ chmod a+x hooks/post-update
$ ./hooks/post-update

$ git diff master  main.h main.c file.h >>  main.patch
$ patch --binary -p1 < main.patch

After failed pull, if you decide to step back instead of resolving the comfits 
$ git reset --hard HEAD

No comments:

Post a Comment