Difference between revisions of "Git Cheat Sheet"

From Genome Analysis Wiki
Jump to navigationJump to search
Line 1: Line 1:
{| style="border-collapse: collapse; font-size: 10pt" border="1" align="left"
+
{| border="1" align="left" style="border-collapse: collapse; "
|+ Git CheatSheet
+
|+ Git CheatSheet  
 
|-
 
|-
 
! colspan="2" | Help
 
! colspan="2" | Help
 
|-
 
|-
| Get Help || git help ''command''
+
| Get Help  
 +
| git help ''command''
 
|-
 
|-
! colspan="2" | Clone/Copy Repo
+
! colspan="2" | Clone/Copy Repo
 
|-
 
|-
| Copy Repo || git clone ''source'' [''destName'']
+
| Copy Repo  
 +
| git clone ''source'' [''destName'']
 
|-
 
|-
 
! colspan="2" | Checking what has Changed
 
! colspan="2" | Checking what has Changed
 
|-
 
|-
| What files changed? || git status
+
| What files changed?  
 +
| git status
 
|-
 
|-
| What changed in a file? || git diff ''fileName''
+
| What changed in a file?  
 +
| git diff ''fileName''
 
|-
 
|-
| What changed in a file between commits? || git diff ''commit1 commit2 fileName''
+
| What changed in a file between commits?  
 +
| git diff ''commit1 commit2 fileName''
 
|-
 
|-
| Check History Logs || git log [''fileName'']
+
| Check History Logs  
 +
| git log [''fileName'']
 
|-
 
|-
 
! colspan="2" | Saving Changes (2 step process)
 
! colspan="2" | Saving Changes (2 step process)
 
|-
 
|-
| 1) Stage Changes || git add ''fileName1 fileName2''
+
| 1) Stage Changes  
 +
| git add ''fileName1 fileName2''
 
|-
 
|-
| 2) Commit Changes || git commit -m “''commit message''”
+
| 2) Commit Changes  
 +
| git commit -m “''commit message''”
 
|-
 
|-
! colspan="2" | Undoing Things
+
! colspan="2" | Undoing Things
 
|-
 
|-
| Undo staging || git reset HEAD ''fileName''
+
| Undo staging  
 +
| git reset HEAD ''fileName''
 
|-
 
|-
| Undo unstaged changes || git checkout -- ''fileName''
+
| Undo unstaged changes  
 +
| git checkout -- ''fileName''
 
|-
 
|-
 
! colspan="2" | Working with a Remote
 
! colspan="2" | Working with a Remote
 
|-
 
|-
| Get the latest updates || git pull
+
| Get the latest updates  
 +
| git pull
 
|-
 
|-
| Share your Changes || git push
+
| Share your Changes  
 +
| git push
 
|-
 
|-
| 1st time pushing branch || git push origin ''branchName''
+
| 1st time pushing branch  
 +
| git push origin ''branchName''
 
|-
 
|-
| Push to Remote || git push origin ''tagName''
+
| Push to Remote  
 +
| git push origin ''tagName''
 
|-
 
|-
| See all branches including remotes || git branch -a
+
| See all branches including remotes  
 +
| git branch -a
 
|-
 
|-
| Base work on a remote branch/merge back to it || git checkout --track origin/''branchName''
+
| Base work on a remote branch/merge back to it  
 +
| git checkout --track origin/''branchName''
 
|-
 
|-
 
! colspan="2" | Tags
 
! colspan="2" | Tags
 
|-
 
|-
| Create a tag || git tag -a ''tagName'' -m "''tag description''"
+
| Create a tag  
 +
| git tag -a ''tagName'' -m "''tag description''"
 
|-
 
|-
| List Tags || git tag
+
| List Tags  
 +
| git tag
 
|-
 
|-
| List tags with certain name || git tag -l ''partialName*''
+
| List tags with certain name  
 +
| git tag -l ''partialName*''
 
|-
 
|-
| Get info on a tag || git show ''tagName''
+
| Get info on a tag  
 +
| git show ''tagName''
 
|-
 
|-
| Push to Remote || git push origin ''tagName''
+
| Push to Remote  
 +
| git push origin ''tagName''
 
|-
 
|-
 
! colspan="2" | Branches
 
! colspan="2" | Branches
 
|-
 
|-
| See what branches exist (current marked with *) || git branch
+
| See what branches exist (current marked with *)  
 +
| git branch
 
|-
 
|-
| Switch branch || git checkout ''branchName''
+
| Switch branch  
 +
| git checkout ''branchName''
 
|-
 
|-
| Create & switch to branch (branches from current one) || git checkout -b ''branchName''
+
| Create & switch to branch (branches from current one)  
 +
| git checkout -b ''branchName''
 
|-
 
|-
| Merge from another branch to this one || git merge ''branchMergingFrom''
+
| Merge from another branch to this one  
 +
| git merge ''branchMergingFrom''
 
|-
 
|-
| See all branches including remotes || git branch -a
+
| See all branches including remotes  
 +
| git branch -a
 
|-
 
|-
| Base work on a remote branch/merge back to it || git checkout --track origin/''branchName''
+
| Base work on a remote branch/merge back to it  
 +
| git checkout --track origin/''branchName''
 
|-
 
|-
| 1st time pushing branch || git push origin ''branchName''
+
| 1st time pushing branch  
 +
| git push origin ''branchName''
 
|-
 
|-
| Delete Local Branch || git branch -d ''branchName''
+
| Delete Local Branch  
 +
| git branch -d ''branchName''
 
|-
 
|-
| Delete Remote Branch || git push origin :''branchName''
+
| Delete Remote Branch  
 +
| git push origin :''branchName''
 
|-
 
|-
 
! colspan="2" | Resolving Merge Conflicts
 
! colspan="2" | Resolving Merge Conflicts
 
|-
 
|-
| 1) Make changes || ''use your favorite text editor''
+
| 1) Make changes  
 +
| ''use your favorite text editor''
 
|-
 
|-
| 2) Delete <<<<<<<, =======, and >>>>>>> || ''use your favorite text editor''
+
| 2) Delete &lt;&lt;&lt;&lt;&lt;&lt;&lt;, =======, and &gt;&gt;&gt;&gt;&gt;&gt;&gt;
 +
| ''use your favorite text editor''
 
|-
 
|-
| 3) Stage the conflict resolution || git add ''nowMergedFile''
+
| 3) Stage the conflict resolution  
 +
| git add ''nowMergedFile''
 
|-
 
|-
| 4) Commit the merge || git commit
+
| 4) Commit the merge  
 +
| git commit
 
|-
 
|-
 
! colspan="2" | Create New “Remote” Repo
 
! colspan="2" | Create New “Remote” Repo
 
|-
 
|-
| Create Repo with only the database info (no source) || git init --bare --shared ''myRepoName''
+
| Create Repo with only the database info (no source)  
 +
| git init --bare --shared ''myRepoName''
 
|-
 
|-
| Push to Remote for the first time || git push origin master
+
| Push to Remote for the first time  
 +
| git push origin master
 
|}
 
|}

Revision as of 18:49, 7 July 2011

Git CheatSheet
Help
Get Help git help command
Clone/Copy Repo
Copy Repo git clone source [destName]
Checking what has Changed
What files changed? git status
What changed in a file? git diff fileName
What changed in a file between commits? git diff commit1 commit2 fileName
Check History Logs git log [fileName]
Saving Changes (2 step process)
1) Stage Changes git add fileName1 fileName2
2) Commit Changes git commit -m “commit message
Undoing Things
Undo staging git reset HEAD fileName
Undo unstaged changes git checkout -- fileName
Working with a Remote
Get the latest updates git pull
Share your Changes git push
1st time pushing branch git push origin branchName
Push to Remote git push origin tagName
See all branches including remotes git branch -a
Base work on a remote branch/merge back to it git checkout --track origin/branchName
Tags
Create a tag git tag -a tagName -m "tag description"
List Tags git tag
List tags with certain name git tag -l partialName*
Get info on a tag git show tagName
Push to Remote git push origin tagName
Branches
See what branches exist (current marked with *) git branch
Switch branch git checkout branchName
Create & switch to branch (branches from current one) git checkout -b branchName
Merge from another branch to this one git merge branchMergingFrom
See all branches including remotes git branch -a
Base work on a remote branch/merge back to it git checkout --track origin/branchName
1st time pushing branch git push origin branchName
Delete Local Branch git branch -d branchName
Delete Remote Branch git push origin :branchName
Resolving Merge Conflicts
1) Make changes use your favorite text editor
2) Delete <<<<<<<, =======, and >>>>>>> use your favorite text editor
3) Stage the conflict resolution git add nowMergedFile
4) Commit the merge git commit
Create New “Remote” Repo
Create Repo with only the database info (no source) git init --bare --shared myRepoName
Push to Remote for the first time git push origin master