Sie sind auf Seite 1von 4

Git commands

 Set-up repo

git clone LINK (htttps/ssh) - run command in a common folder, in that place it will create a folder with the repo's name

git remote (see set remote repo)


git remote -v (see all remote repos)
git remote add origin SOURCE (add a remote repo, https/ssh)

 Status & log

git status (see latest changes)

git log (see all commits)


git log --oneline (a commit per line)
git log --oneline | wc -l (count commits)
git log --oneline --graph (graphical view on branches)
git log --oneline --graph --all --decorate (graphical view on branches with tags and head)
git shortlog (authors and their commits)
git shortlog -sne (count, name, email)
git reflog (references, shows head history)

git show HEAD (shows present head)

git diff (show differences)


git diff --cached (show the differences with the staging area)

Attribute an alias to a long command


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

 Commit & Push

git add -u (updated)


git add -A (addition/removal)
git add . (all changes)

git commit -m "Message" (commit the added changes)


git commit -am "Message" (skip add stage)

git push (if branch upstream already set)


git push origin master
git push origin BRANCH (if doesnt exists, creates it)
git push origin local_branch:remote_branch
git push origin :remote_branch (delete remote branch)

 Update repo

git fetch (get data from origin)


git fetch origin (specify witch origin)
git merge origin/master

git pull (does git fetch; git merge origin/master)

git branch --set-upstream master origin/master (setting correspondence between local and remote
branches)
git pull
or
git pull origin master

 Branching

git branch (list of branches)


git branch -r (list of remotely branches)

git branch NAME (create a branch)


git branch NAME 94a5b1 (create branch from specified commit)

git branch -m NAME1 NAME2 (rename a branch)


git branch -d NAME (

git checkout NAME (move to branch)


git checkout -b NAME (create branch and moves head to it)

 Merging

git merge branch1 branch2 (merge specified branch to current branch)


(git branch -d BRANCH dont forget to delete branch after merge)
git merge --squash (merge as a single commit)

If there are conflicts, git will automatically add tags in specified files.
As this:
<<<<<< HEAD
what is in current branch
====
what is in merging folder
>>>>>>>>>> 53fsd534dgghs6

Configure git to use kdiff3


git config --global merge.tool kdiff3
git config --global mergetool.kdiff3.cmd '"C:\\Program Files\\KDiff3\\kdiff3" $BASE $LOCAL
$REMOTE -o $MERGED'

git mergetool (kdiff3) - 3 way merge tool

Base - the common commit from where they come from


Local - the current branch
Remote - the merging branch
**dont forget to remove the .orig file**
rm file.html.orig

*cherry-pick to transfer commits (aka partial merge)


git cherry-pick COMMIT (apply specified commit to current branch)
(after cherry-pick merge is safe, he know about that commit and wont reapply it)

 Stashing

*You can stash (aka hide) the current changes while you checkout to another branch or work at
something else, commit, then unstash and continue

git stash (stash uncommitted changes)


git stash list (show stashed changes)
git stash apply (restore the changes)
git stash pop (does apply and removes it from the list)
git stash drop (removes 1 change)
git stash branch NAME (creates the branch, stash the changes, checkout to it)

 Reset changes

git checkout FILE (revert file to initial committed state)


git reset --hard (revert all changes)
git reset --soft HEAD~1 (delete last commit, but you can see all changes as uncommitted, correct
them, and recommit)
git reset --hard HEAD~1 (delete last commit and all the changes entirely)

git clean -n (see what he gonna do)


git clean -f (force, remove changes)
.gitignore file (just add files/folders to be ignored)

 Tags

*placing a notice at one stage of a branch (the present commit) to specify that until that point it
reached a certain point.
git tag (list of tagged versions)

git tag v1.0 (tag brach as v1.0)


git tag -a v1.0 -m "Message" (tag with notes)
git tag -s v1.0 -m "Message" (signed tag, mandatory message, secured by passphrase)

git tag -v v1.0 (verify a tag)

**Git doesnt pull tags by default (in torotise check the tags option)**
git push --tags (needed to push the tags too)

Das könnte Ihnen auch gefallen