My list of useful Git commands

After using Git for last three years extensively, I have compiled this list of commands I use frequently. Occasionally, I rely on posts like this one to get me out of the pickle.

Help

git help <commandName> (dont write git in front of it.. ex: git help remote) 

Git Staging

New Files -> git add .
Unstage/Delete -> git add -u
clean -> git clean -f

Undo

 Undo -> git reset --hard
 Undo Commit -> git reset --soft[hard] Head~1

Clone a Repo

clone  -> git clone [ssh/https Url]

Stash

stash -> git stash
apply -> git apply
drop -> git stash drop
clear -> git stash clear
pop and apply -> git stash pop
list -> git stash list

Tag

Create-> git tag [tagName]
show -> git show [tagName]
Push To Remote ->git push --tags
             git push origin [tagName]

Log

Fancy log -> git log --graph --oneline --all --decorate
Reference log 
(shows where the head was..useful for recovering delete) 
          -> git reflog

Alias

Ex:
Run -> git config --global alias.lga "log --graph --oneline --all --decorate"
Use -> git lga

Branching

create -> git branch [branchName]
create checkout -> git checkout -b [branchName]
checkout remote branch -> git checkout [remoteBranchName]
Move branch -> git branch -m [oldBranchName] [newBranchName]
Delete Branch -> git branch -d [branchName]
Delete Remote branch -> git push origin --delete [branchName]
Recover Deleted Branch -> git branch [branchName] [SHA1Hash]
From Tag -> git branch [branchName] [TagName]
create from SHA1 hash -> same as above

Push changes

git push <originname> <branchname>

Merge

Steps: 
    1) Checkout the  host branch 
    2) git merge [branchToMerge]

conflict -> git mergetool

Rebasing

replay all commits one at a time and make it look like they were always a part of a branch
Steps:
    1)Checkout the branch you want for Ex: Feature1
    2)Run-> git rebase [branchNameYouWanttoApplyTheFeatureOn]

Cherry-pick

steps:
    1)Checkout the branch
    2)Run -> git cherry-pick [SHA1]

Add multiple origins

add new origin with fetch url -> git remote add --fetch <originName> <fetchurl>
Setup push url for the origin -> git remote set-url <originName> --push <pushurl>
show all origins -> git remote -v show
fetch all the remotes ->  git remote update
remove stale branches -> git remote prune origin

Misc ((not all are Git related)

create-> touch fileName
remove -> rm fileName
See config -> cat ~/.gitconfig

After using Git for last three years extensively, I have compiled this list of commands I use frequently. Occasionally, I rely on posts like this one to get me out of the pickle. Help git help <commandName> (dont write git in front of it.. ex: git help remote)…

Read More

Be a Git Ninja deck

It was a lot fun presenting at the Boston code camp 21.  The slide deck with all the links is below:

It was a lot fun presenting at the Boston code camp 21.  The slide deck with all the links is below:…

Read More

Git for Source Control

I have worked with SVN and VSS for source control. Both are centralized source control system. Git is distributed. It has several advantages over centralized ones. Just to mention a few:

1) Branching is very easy,cheap and fast. This makes experiments an easy task.

2) You are always working on a local copy of repo and disconnected from the server.

3) Git is incredibly fast.

4) Commands are easy.

5) Gui tools have matured and are getting better.

Basics of git are at git-scm.com

Great insight from community on concepts such branching , cloning and forking are at this post

You can get awesome visual studio git tools here The documentation is nice and readable. You can get it working within minutes.

Github.com has nice tools. It is widely used for git repos but they charge for private repos. This posthas a number of free private source repo options. I personally like bitbucket. It is convenient.

Finally, learn all the details with Rob Conery at Tekpub and become a git ninja!

Git is dirt simple. It works and fits perfectly to me.

I have worked with SVN and VSS for source control. Both are centralized source control system. Git is distributed. It has several advantages over centralized ones. Just to mention a few: 1) Branching is very easy,cheap and fast. This makes experiments an easy task. 2) You are always working…

Read More