Starting Git git

Create your fist local depot

    mkdir red
    cd red
    git init
    

First, some commands :

    git status # list of modifications
    git add .  # add all change 
    git commit -m "message" # save all change

    git remote -v # list dépots

    git branch # list all branch
    git checkout -b branch_name # create a new branch and use it
    git checkout master # change to branch master
    git branch -a # list all branch, local and remote
    git branch -d branch_name # delete branch_name
    git push origin branch_name # puts the branch to the distant depot
    git push origin master # puts the modification to the distant depot
    git merge branch_name # fusion with master and branch_name

    git tag tag_name # create a new tag

    git log # show the log
    git log --oneline -2 # last 2 commit
    git log -1 --pretty=%B # last commit message
    

Windows explorer integration : disable contextual menu

Context menu in explorer are too long, and since i use only command line for git, let’s do this :

cd \Git\git-cheetah
regsvr32 /u git_shell_ext.dll

A better git log : aliasing command

From https://coderwall.com/p/euwpig?i=3&p=1&t=git, the command is :

git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

You can add a git alias for this :

git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

And now use it with a simple git lg or git lg -1 for just the last log :)

In the same way, this alias list all file modified by commit :

git config --global alias.lgf "log --pretty=format:'%Cred%h%Creset%d - %C(yellow)%s%C(bold blue) <%cn>' --decorate --numstat"

Use it : git lgf -3.

Classic alias (take from several pages)

You can manage your alias more easly in editing the [alias] section in your .gitconfig file.

st = status -s
cl = clone
ci = commit
co = checkout
br = branch 
logtree = log --graph --oneline --decorate --all
changes = diff --name-status
ll = log --stat --abbrev-commit

Git completion

Don’t forget useful git completion help ! just test it : git stat<tab> for completion or git sta<tab><tab> for a list of available commands.

Config Tips

Working on windows, publishing on github, you can have sometime problem with case filename management.

So, change the case config :

git config core.ignorecase false

Git tag

Easy way : just :

git tag v0.1.2

Nota : By default, the git push command doesn’t transfer tags to remote servers (see http://git-scm.com/book/en/Git-Basics-Tagging). Transfer by :

git push origin --tags

How to discard all change since the last commit :

First discard modified files :

git checkout -- .

And discard the new untracked files (first with -n just for checking, and for real without it)

git clean -f -d -n 

Create a new Rails 4 app :

    cd /c/www
    rails new red -B  # don't check the gem library now
    bundle check
    bundle install --local
    

And first commit in Git

    git status
    git add --all
    git status
    git commit -m 'initial commit, rails empty'
    git tag v0.0 -m 'initial version'
    

Check this one :


comments powered by Disqus