User Tools

Site Tools


git

Git

Checkout Remote Branch

http://stackoverflow.com/questions/1783405/git-checkout-remote-branch

$ git fetch origin
$ git checkout -b test origin/test

Config

$ vim .gitconfig

[user]
  name = XXX
  email = xx@yy.zz
[format]
  pretty = oneline
[color]
  ui = true
[alias]
  s = status --short
[core]
  editor = vim                    

Basic Editing

Commit:

git add FILE
git commit -m 'DESCRIPTION'

Tag:

git tag TAGNAME commit-hash

Create New Branch:

git branch XXX

Switch Branch:

git checkout XXX

Delete uncommitted changes:

git reset --hard

Push To Server

:!: DO NOT EDIT ON SERVER :!:

1 - Create repo on server, tweak settings

$ ssh server
$ cd X
$ git init .
$ git config receive.denyCurrentBranch ignore
$ vim .git/hooks/post-receive

#!/bin/sh

# Update the working tree after changes have been pushed here
cd ..
env -i git reset --hard

$ chmod +x .git/hooks/post-receive

2 - Create remote on server

$ git remote add live ssh://user@example.com/home/example/public_html

3 - Push to server

$ git push live origin

Sources:

Client, Client, Server Trickery

For adding remotes, etc – Don't forget to point out the protocol, i.e.

ssh://git@li345-114.members.linode.com/var/git/XXX

Basic Setup

Client A Client B Server Comment
adduser –home /var/git git
chown git:git /var/git
su - git
cd /var/git
mkdir proj
git init –bare . Init bare repository
cd /proj
git init .
touch README
git add README
git commit -m 'first'
git remote add origin git@server/var/git/proj Adds origin remote
git push origin master Push master to origin
git clone git@server:/var/git/proj Clone origin

Push Changes

Client A Client B Comment
git add X
git commit -m 'Y'
git push origin master
git pull

Push Other Branch

Client A Client B Comment
git checkout -b xyz Create branch xyz
git add X
git commit -m 'Y'
git push origin xyz Push branch xyz to origin
git pull origin xyz Pull branch xyz from origin
git checkout xyz Checkout branch xyz

NB: git pull does git fetch, then git merge

Sources

git.txt · Last modified: 2013/10/08 11:11 by Volker