Slion.net>Dev>VersionControlSystem>GitHome

Git

Git is a free and open source distributed version control system.

Usage

Here is a bunch of git commands I commonly use.

Add specified file to your list of commits

git add <file>

Amend the current changes

Typically done after cherry-pick from gerrit.
git commit --amend

Push your current changes for review to gerrit remote master

git push origin HEAD:refs/for/master

Fetch and rebase from the remote repository

git pull --rebase
If you do not have any changes in your current branch the rebase argument can be omitted as it we do a fast forward.

Update all submodules

git submodule update --init --recursive

Delete a local branched named 'test'.

git branch -d test
Will fail if the specified branch has orphaned changes.

Force deletion of a local branched named 'test'

git branch -D test

Display all branches even the remote once

git branch -av

Switch to a branch named 'local'

git checkout local
Will fail if the branch does not exists

Shows your local branches

git branch
Also marks your current branch.

Create a local branch from a remote one

git checkout -b test-local remotes/origin/test

Shows which branch you have currently checked out and the status of local files

git status

Run this from your working branch to rebase from your local master

git rebase master

Run this from any branch to rebase and checkout your branch

git rebase master mybranch

List the history, last change first

git log

Revert all you changes

git reset --hard

Abort a cherry pick

git reset --merge

Stash management

git stash save
git stash apply
git stash pop
git stash list

Rebase

git rebase -i master branch-name-to-rebase

Merge changes from the specified branch onto the current branch

git merge mybranch

Merge back to master

git merge --no-ff mybranch

Tortoise GIT log

tgit log

To cherry-pick a merge. -m 1 reference to the first parent of the merge as listed on gerrit

git cherry-pick -m 1 FETCH_HEAD

To delete your latest commit from your history

USE THIS CAREFULLY, YOU ALSO LOOSE ALL LOCAL CHANGES
git reset --hard HEAD^

Create a patch from the latest commit

git format-patch -n HEAD^

Apply a patch

git apply mypatch.patch

References