My git branch operations and remote cheat sheet

Some useful git command with branches and remote repositories.

Remote operations

List remotes:

git remote -v

Add remote gitosis server:

git remote add <remote_name> git@myhostname.com:my_project_name.git
git push <remote_name> master

Where master is your branch name

Main git branch orperations

list branches:

git branch -v

-v is optional, you use it to get more verbose output

Create new branch:

git checkout -b <new_branch_name>

Merge into :

git checkout <a_branch>
//do something
git commit -am 'I did something'
git checkout <b_branch>
git merge <a_branch>

Delete branch:

git branch -d <branch_name>

Reset an old commit state

Warning: you always clone your repository before try these commands!

You can undo everything you've made since last commit. Uncommited modifications will be lost.

git reset --hard HEAD

Remove the last 3 commit. Commits will be removed from git forever:

git reset --hard HEAD~3

Undo uncommited changes for a specified file:

git checkout -- <file_name>
Blog categories:  Programming  Linux

Add new comment