Git Introduksjon

Teis Lindemark

Git

  1. A completely ignorant, childish person with no manners.
  2. A person who feels justified in their callow behaviour.
  3. A pubescent kid who thinks it's totally cool to act like a moron on the internet, only because no one can actually reach through the screen and punch their lights out.
http://www.urbandictionary.com/define.php?term=Git

Hva er Git?

  • Versjonskontrollsystem (VCS)
  • Distribuert VCS
  • Laget av Linus Torvalds i 2005
  • Sterk støtte for ikke linjær utvikling
  • Git kan bli brukt som en server ut av boksen

Hvorfor git?

  • Sterk støtte for ikke linjær utvikling
  • Sterk støtte for offline jobbing
  • Muligheten for lokale brancher
  • Enkelt ikke blande funksjonalitet under utvikling

Git setup

  • git config --global user.name "Ditt navn"
  • git config --global user.email "Ditt navn@acos.no"
https://git-scm.com/downloads

Start git bash

$ ssh-keygen

Basic kommandoer

git clone

Clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository, and creates and checks out an initial branch that is forked from the cloned repository’s currently active branch.

https://git-scm.com/docs/git-clone

git clone git@git.intern.acos.no:teis/git-intro.git

git pull

Incorporates changes from a remote repository into the current branch. In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.

More precisely, git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch. With --rebase, it runs git rebase instead of git merge.

https://git-scm.com/docs/git-pull

git add

This command updates the index using the current content found in the working tree, to prepare the content staged for the next commit. It typically adds the current content of existing paths as a whole, but with some options it can also be used to add content with only part of the changes made to the working tree files applied, or remove paths that do not exist in the working tree anymore.

https://git-scm.com/docs/git-add

git commit

Stores the current contents of the index in a new commit along with a log message from the user describing the changes.

https://git-scm.com/docs/git-commit

git push

Updates remote refs using local refs, while sending objects necessary to complete the given refs.

https://git-scm.com/docs/git-push

git fetch

Fetch branches and/or tags (collectively, "refs") from one or more other repositories, along with the objects necessary to complete their histories. Remote-tracking branches are updated (see the description of below for ways to control this behavior).

https://git-scm.com/docs/git-fetch

git checkout

Updates files in the working tree to match the version in the index or the specified tree. If no paths are given, git checkout will also update HEAD to set the specified branch as the current branch.

https://git-scm.com/docs/git-checkout

git branch

git-branch - List, create, or delete branches

https://git-scm.com/docs/git-branch

git rebase

git-rebase - Reapply commits on top of another base tip

https://git-scm.com/docs/git-rebase

Git alias

Hva er det?

  • "Snarvei" til git kommandoer
  • Kan være kortform av enkle git kommandoer
  • Kan også være snarvei til lange kompliserte git kommandoer

Hvordan definere alias

  • Fra kommandolinje
  • git config --global alias.XX git_kommando

  • Endring rett i .gitconfig filen

Noen enkle alias

							
								$ git config --global alias.co checkout
								$ git config --global alias.br branch
								$ git config --global alias.ci commit
								$ git config --global alias.st status
							
						

git log --branches --not --remotes --simplify-by-decoration --decorate --oneline

...

Andre nyttige kommandoer

git stash

git-stage - Add file contents to the staging area

https://git-scm.com/docs/git-stage

Verktøy