Skip to content

Instantly share code, notes, and snippets.

@hakonrossebo
Last active February 17, 2018 21:39
Show Gist options
  • Save hakonrossebo/39f263253a6dc288870477ed0543f553 to your computer and use it in GitHub Desktop.
Save hakonrossebo/39f263253a6dc288870477ed0543f553 to your computer and use it in GitHub Desktop.
Git commands and config

Pull requests

git remote add  upstream xyz.git
git fetch upstream
git branch --set-upstream-to=upstream/master master
  eller: git checkout -b test origin/test
  eller: git checkout --track -b newFeature upstream/master
git merge upstream/master 
eller
git rebase upstream/master
  -Eventuelt merge - når ferdig: git rebase --continue
push -u -f origin branchname

Git pull og rebase

git pull --rebase origin master

Git Stashi:

git stash
git stash pop
git stash list

Vise logg

git log
git log --pretty=oneline --abbrev-commit

Delete stuff

git reset --hard # removes staged and working directory changes

NB! Forsiktig!!!

git clean -f -d # remove untracked
git clean -f -x -d # CAUTION: as above but removes ignored files like config.
git clean -fxd :/ # CAUTION: as above, but cleans untracked and ignored files through the entire repo (without :/, the operation affects only the current directory)

Go back to commit:

git revert 073791e7dd71b90daa853b2c5acc2c925f02dbc6

Soft reset (move HEAD only; neither staging nor working dir is changed):

git reset --soft 073791e7dd71b90daa853b2c5acc2c925f02dbc6

Undo latest commit:

git reset --soft HEAD~

Mixed reset (move HEAD and change staging to match repo; does not affect working dir):

git reset --mixed 073791e7dd71b90daa853b2c5acc2c925f02dbc6

Hard reset (move HEAD and change staging dir and working dir to match repo):

git reset --hard 073791e7dd71b90daa853b2c5acc2c925f02dbc6

Credential helper

git config --global credential.helper wincred

Enkle git kommandoer:

Opprett prosjekt

-Git init

Legge til alle filer

 Git add .

Commit

Git commit - "kommentar"

Git Config

Gitignore

Sette opp ssh keys

Ssh -keygen -t rsa -C "email"
Ssh -T git@bitbucket.org (sjekker kobling)

Sette config

git config --global user.name "Hakon Rossebo"
git config --global user.email "my@email.com

Editer config i standard editor:

git config --global --edit 

-eller åpne .gitconfig i home

Lage zip arkiv

git archive --format zip --output filename.zip master

Alias til .gitconfig

[alias]
	lg = log --oneline --graph --decorate
	s = status
	co = checkout
	cob = checkout -b
	bd = branch -d
	aa = add .
	ac = !git add . && git commit -am
	ss = status -s
	diffy = difftool -y

Remote:

Se alle remotes

git remote -v

Legge til remote

git remote add upstream xyz.git

Fjerne remote

git remote rm origin

Vis remote branches

git branch -r

Sammenligne

git diff origin/master..master

Push branch to origin remote

git push origin -u FixtureDataImprovements

Lage en ny lokal branch som er synkronisert med remote branch

git checkout --track -b LanguageTranslations origin/LanguageTranslations
git checkout -b [branch] [remotename]/[branch]

eller

git checkout --track origin/serverfix

for å sette en eksisterende branch til å tracke en remote:

git branch -u origin/serverfix

Andre Git linker:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment