JosefJezek
1/10/2014 - 2:40 AM

GIT

GIT

GIT

Learning Git

Hosting

Setup

sudo apt-get install gitk
git config --global user.email ""
git config --global user.name ""
git config --global push.default current

git config --global alias.ch checkout
git config --global alias.br branch
git config --global alias.co 'commit -am'
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
git config --global alias.visual '!gitk'

Remove last commit git reset HEAD^

URL

vi .git/config

[remote "origin"]
  url = ssh://github_my/josefjezek/repo

Generate Key

ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -C "your_email@youremail.com"
ssh-add ~/.ssh/id_rsa_github
ssh-add -l
cat ~/.ssh/id_rsa_github.pub

SSH config

Host github
    HostName github.com
    User git
    VerifyHostKeyDNS yes
    IdentityFile ~/.ssh/id_rsa_github

Commit

git add index.html | git add .
git commit -a -m "First pages commit"
git push origin gh-pages

Diff

git diff 0da94be  59ff30c > my.patch
git apply my.patch

Update

git commit -a -m "Update"
git pull origin gh-pages

Tag

Show Tags

git fetch --tags
git tag -l

Checkout Latest Tag

# Get new tags from remote
git fetch --tags

# Get latest tag name
latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)

# Checkout latest tag
git checkout $latestTag

Fix

gitignore

git rm -r --cached .
git add .
git commit -m ".gitignore is now working"

Merge two different repository

if you have two differents repositry (first and second) to merge in one even in local :

we create a new git repository ans make an initial commit :

mkdir newRepository
git init
touch .gitignore
git add .gitignore
git commit .gitignore -m 'init'

we fetch and merge the first

git remote add first pathTo/first
git fetch first
git merge first/master

we fetch and merge the second

git remote add second pathTo/second
git fetch second
git merge second/master

Resources