Git. Often used command set

Shows git tree of all commits

git log

Moving around in Git: - destination by:

HEAD^
HEAD^^^
HEAD~
HEAD~3
<branch>^
<branch>~2
<branch>
- or by hash of commit:

fed2da64c0efc5293610bdd892f82a58e8cbc5d8
- commands:

git checkout <destination>
git checkout HEAD~;
git checkout HEAD^2;
git checkout HEAD~2;
git checkout HEAD~^2~2
git branch -f <branch> <destination>
git branch <branch> master^~2
- feature in merge commit

git checkout master^1 # goes to the first ancesstor
git checkout master^2 # goes to the second ancesstor

Creates new feature branch without checking out

git branch <feature-branch-name>
git branch <feature-branch-name> HEAD~

Creates new feature branch and check out

git checkout -b branch <feature-branch-name> HEAD~

Rebasing (target branch ia a current branch)

git rebase <source-branch>
- with hash of commit

git rebase <Commit>
- with interactive mode

git rebase -i HEAD~4
- for rebasing target branch with source branch

git rebase <source-branch> <target-branch>

Reversing changes: - only local

git reset HEAD~1
- for share with remote

git revert HEAD
- only for changing last commit message

git commit --amend

Adds commits (copies) to current branch in given order

git cherry-pick <Commit1>, <Commit2>, ...

Tagging commits

git tag <tag-name>
git describe <place>
OUTPUT: <tag>_<numCommits>_g<hash>

Merging changes (target branch ia a current branch)

git merge <source-branch>

Pulling changes from remote
- in merging way
git pull is equal to git fetch; git merge origin/master

git pull
git push

git fetch
git merge origin/master
git push
- in rebase way
git pull --rebase is equal to git fetch; git rebase origin/master

git pull --rebase
git push

git fetch
git rebase origin/master
git push
- when source is related to remote and destination to local (if branch doesn't exist it will be created)

git pull origin <source>:<destination>
git pull origin foo is equal to git fetch origin foo; git merge origin/foo
git pull origin bar~1:bugFix is equal to git fetch origin bar~1:bugFix; git merge bugFix

- Remote tracking (when some branches can be linked by origin/master independently of master branch)

git checkout -b foo origin/master
git pull

git checkout -b foo origin/master
git commit
git push
- when branch exists

git branch -u origin/master foo
git branch -u origin/master

git branch -u foo o/master
git commit
git push

Pushing changes to remote

git push origin <place>
- source is related to local and destination to remote (if branch doesn't exist it will be created)

git push origin <source>:<destination>
git push origin master^^:foo
git push origin foo:master

Removes foo branch in remote

git push origin :foo

Adds bar branch in local

git fetch origin :bar

No comments :

Post a Comment