Versjonskontroll med Git

mkdir alpha
cd alpha

echo "hello" > world.txt

git init

git status
git add world.txt
git status

git commit -m "Initial commit"
git status
git log

git init

git log --all --oneline --graph --decorate
git config --global alias.lg "log --all --oneline --graph --decorate"
git lg

bruk av alias

echo "world" >> world.txt

git status
git add world.txt
git commit -m "Added world to world.txt"
git status
git lg

cat world.txt
git checkout HEAD~1
git lg
cat world.txt
git checkout master
git lg
cat world.txt

git checkout (commits)

echo "blabla" >> world.txt
cat world.txt
git checkout world.txt
cat world.txt
git status

git checkout (files)

cd ..
git clone alpha beta
cd beta
ls
git lg

cd ../alpha
echo "print 'hello world'" > hello.py
git add hello.py
git commit -m "Added hello.py initial version"

git lg
cd ../beta
git lg

git fetch
git lg
git merge
# git fetch + git merge = git pull
git lg
ls

git clone / git pull

cd ..
git clone --bare alpha common.git
cd common.git
ls
cd ..

git clone common.git gamma
cd gamma
ls

cd ../alpha
git remote add origin ../common.git
git push -u origin master
git lg

cd ../beta
git remote -v
git remote remove origin
git remote add origin ../common.git
git push -u origin master
git lg

git clone --bare / remotes

cd ..
git clone --bare alpha common.git
cd common.git
ls
cd ..

git clone common.git gamma
cd gamma
ls

cd ../alpha
git remote add origin ../common.git
git push -u origin master
git lg

cd ../beta
git remote -v
git remote remove origin
git remote add origin ../common.git
git push -u origin master
git lg

git clone --bare / remotes

echo "Tiger" > cats.txt
git add cats.txt
git commit -m "Added cats.txt - a list of cat names"
git fetch
git lg
git push
git lg

cd ../alpha
echo "Fido" > dogs.txt
git add dogs.txt
git commit -m "Added dogs.txt - a list of dog names"
git fetch
git lg
git merge origin/master --no-edit
git lg

basic merge

# for å "angre" merge vi gjorde:
git reset --keep HEAD~1


git lg
# git stash
git rebase origin/master
# git stash pop
git lg
git push
git lg

# git stash og git stash pop brukes
# dersom man har filer man har endret
# men ikke vil committe

basic rebase

echo "Fluffy" >> cats.txt
git commit -am "Added Fluffy to list of cat names"
git push

cd ../beta
echo "Shadow" >> cats.txt
git commit -am "Added Shadow to list of cat names"

git pull
nano cats.txt
git add cats.txt
git commit -m "Merged list of cat names"
git lg

basic merge m/konflikter

# igjen, for å "angre" merge vi gjorde:
git reset --keep HEAD~1

git fetch
git rebase
nano cats.txt
git add cats.txt
git rebase --continue
git lg

git push

basic rebase m/konflikter

git checkout -b fancyhello
echo "print sum(range(1, 101))" >> hello.py
git commit -am "Math demo added to hello.py"
git lg

git checkout master
echo "Bo" >> dogs.txt
git commit -am "Added dog name Bo"
git lg

git checkout fancyhello
git rebase master
git checkout master
git merge fancyhello

branching

GitHub

https://education.github.com

  • Gratis til open source, private repo koster penger
  • 5 gratis private repo som student

 

BitBucket

https://bitbucket.org

  • Gratis private repo, samarbeid med over 5 personer koster penger
  • Alt gratis som student

GitHub sin interaktive intro til Git:

http://try.github.io/

 

Interaktiv tutorial til mer avansert branching og rebasing:

http://pcottle.github.io/learnGitBranching/

 

En fin liste med nyttige Git-kommandoer:

https://gist.github.com/hofmannsven/6814451

Hvordan bruke Git til å enkelt oppdatere en nettside ("push-to-deploy"):

http://toroid.org/ams/git-website-howto

 

Artikkel om hvordan Git faktisk fungerer:

http://maryrosecook.com/blog/post/git-from-the-inside-out

Mine alias

	unstage = reset HEAD
	preview = diff --cached
	lg = !git --no-pager lgl -15
	lgl = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
	st = status -s
	co = checkout
	wdiff = diff --color-words

	# Remove the old tag with this name and tag the latest commit with it.
	retag = "!r() { git tag -d $1 && git push origin :refs/tags/$1 && git tag $1; }; r"

	alias = !git config --list | fgrep alias. | sed 's/alias\\.\\([^=]*\\)=\\(.*\\)/\\1\\\t => \\2/' | sort | cut -c -80

Versjonskontroll med Git

By Erik Vesteraas

Versjonskontroll med Git

(Fra 2015, se heller den andre presentasjonen om versjonskontroll)

  • 1,559