Posted By

stayce on 04/08/10


Tagged

git cheat stast


Versions (?)

git temporary stash then update


 / Published in: Bash
 

URL: http://github.com/guides/git-cheat-sheet

  1. 234 git branch #which branch
  2. 235 git status
  3. 236 git add . #add modded files
  4. 237 git stash #temp stash with no name
  5. 238 git status
  6. 240 git checkout master #switch to master branch
  7. 241 git pull #TO UPDATE YOUR LOCAL BRANCH FROM THE REMOTE SERVER
  8. 242 git checkout dev
  9. 243 git rebase master #TO MAKE SURE THAT YOUR NEW BRANCH GETS CHANGES FROM THE MASTER BRANCH (WHERE EVERYBODY ELSE IS WORKING) USE THE REBASE COMMAND
  10. 244 git stash apply
  11.  
  12. ===OTHERS===
  13. A Practical Git GUIDE
  14. (credit: notes extracted from GIT screencast at http://www.peepcode.com.)
  15.  
  16. CONFIGURE
  17. identify yourself to git: email and your name
  18.  
  19. git config --global user.name "David Beckwith"
  20.  
  21. git config --global user.email "[email protected]"
  22.  
  23. To view all options:
  24.  
  25. git config --list
  26.  
  27. OR
  28.  
  29. cat .git/config
  30.  
  31. SET UP ALIASES
  32. git config --global alias.co checkout
  33.  
  34. VIEW YOUR CONFIGURATION
  35. cat .gitconfig
  36.  
  37. TO IGNORE WHITESPACE (Ruby is whitespace insensitive)
  38. git config --global apply.whitespace nowarn
  39.  
  40. Some nice aliases:
  41.  
  42. gb = git branch gba = git branch -a gc = git commit -v gd = git diff | mate gl = git pull gp = git push gst = git status
  43. START USING GIT
  44. git init
  45.  
  46. TO IGNORE SOME FILES
  47. Add a file in the root directory called .gitignore and add some files to it: (comments begin with hash)
  48.  
  49. *.log db/schema.rb db/schema.sql
  50. Git automatically ignores empty directories. If you want to have a log/ directory, but want to ignore all the files in it, add the following lines to the root .gitignore: (lines beginning with �!� are exceptions)
  51.  
  52. log/*
  53. !.gitignore
  54.  
  55. Then add an empty .gitignore in the empty directory:
  56.  
  57. touch log/.gitignore
  58.  
  59. TO SCHEDULE THE ADDITION OF ALL FILES TO THE NEXT COMMIT
  60. git add .
  61.  
  62. TO SEE THE STATUS
  63. git status
  64.  
  65. TO COMMIT
  66. git commit -m "First import"
  67.  
  68. TO SEE WHAT HAS BEEN COMMITTED
  69. git ls-files
  70.  
  71. TO SCHEDULE DELETION OF A FILE
  72. git rm [file name]
  73.  
  74. TO COMMIT ALL CHANGES IN FILES IN THE CURRENT REPOSITORY
  75. git commit -a
  76.  
  77. TO SCHEDULE THE ADDITION OF AN INDIVIDUAL FILE TO THE NEXT COMMIT
  78. git add [file name]
  79.  
  80. TO VIEW THE DIFFERENCE AS YOU COMMIT USE THE -v OPTION
  81. git commit -v
  82.  
  83. TO COMMIT AND TYPE THE MESSAGE ON THE COMMAND LINE USE THE -m OPTION
  84. git commit -m "This is the message describing the commit"
  85.  
  86. TO COMMIT AND GET AUTOMATICALLY ANY CHANGES FROM OTHER PEOPLE USE THE -a OPTION
  87. git commit -a
  88.  
  89. THE NORMAL COMMIT COMMAND:
  90. git commit -a -v
  91.  
  92. TO VIEW A LOG OF YOUR COMMITS
  93. git log
  94.  
  95. TO VIEW A LOG OF YOUR COMMITS WITH A GRAPH TO SHOW THE EXTENT OF THE CHANGES
  96. git log --stat
  97.  
  98. TO HAVE PAGINATION WHEN VIEWING THE LOG FILE USE THE -v OPTION
  99. git log -v
  100.  
  101. TO VISUALIZE YOUR CHANGES
  102. gitk --all
  103.  
  104. TO CREATE A NEW TAG AND PUSH IT ON THE REMOTE BRANCH
  105. git tag "v1.3"
  106. git push --tags
  107.  
  108. TO CREATE A NEW BRANCH
  109. git branch [name of your new branch]
  110.  
  111. TO PUSH THE NEW BRANCH TO A REMOTE REPOSITORY
  112. git push origin [new-remote]
  113.  
  114. TO PULL A NEW BRANCH FROM A REMOTE REPOSITORY
  115. git fetch origin [remote-branch]:[new-local-branch]
  116.  
  117. TO VIEW ALL OF THE EXISTING BRANCHES
  118. git branch
  119.  
  120. TO VIEW A LIST OF ALL BRANCHES
  121. git branch -a
  122.  
  123. TO SWITCH TO ANOTHER BRANCH
  124. The state of your file system will change after executing this command.
  125.  
  126. git checkout [name of the branch you want to switch to]
  127.  
  128. OR
  129.  
  130. git co [name of the branch you want to switch to]
  131.  
  132. TO MAKE SURE THAT YOUR NEW BRANCH GETS CHANGES FROM THE MASTER BRANCH (WHERE EVERYBODY ELSE IS WORKING) USE THE REBASE COMMAND
  133. git rebase master
  134.  
  135. TO MERGE YOUR NEW BRANCH INTO THE MASTER BRANCH
  136. First, switch back to the master branch:
  137.  
  138. git co master
  139.  
  140. Check to see what changes you�re about to merge together, compare the two branches:
  141.  
  142. git diff master xyz
  143.  
  144. If you�re in a branch that�s not the xyz branch and want to merge the xyz branch into it:
  145.  
  146. git merge xyz
  147.  
  148. TO REVERT YOUR CHANGES to before the merge.
  149. git reset --hard ORIG_HEAD
  150.  
  151. TO RESOLVE CONFLICTS just edit your file.
  152. Remove the markings, add the file, then commit.
  153.  
  154. TO CREATE A BRANCH AND SWITCH TO THE BRANCH IN ONE MOVE:
  155. git checkout -b [name of new branch]
  156.  
  157. TO CREATE A �CLIPBOARD� or �STASH� OF CHANGES THAT ARE NOT YET COMMITED (SO THAT YOU CAN SWITCH TO ANOTHER BRANCH IN THE MIDDLE OF YOUR CHANGES.), CREATE A STASH.
  158. git stash "Put a message here to remind you of what you're saving to the clipboard"
  159.  
  160. TO SWITCH AWAY FROM THE CURRENT BRANCH
  161. git co [branch you want to switch to]
  162.  
  163. Do whatever
  164. Then switch back to the stashed branch
  165.  
  166. git co [the stashed branch]
  167.  
  168. TO VIEW THE LIST OF STASHES
  169. git stash list
  170.  
  171. TO LOAD BACK THE �CLIPBOARD� OR �STASH�
  172. git stash apply
  173.  
  174. Now you can continue to work where you were previously.
  175.  
  176. TO DELETE A BRANCH THAT IS NOT USED ANYMORE, but already merged into the current branch. (TO CLEAN UP)
  177. git branch -d [name of branch you want to delete]
  178.  
  179. TO DELETE AN UNMERGED BRANCH
  180. git branch -D [name of branch you want to delete]
  181.  
  182. TO DELETE THE STASH. (ERASE THE �CLIPBOARD� FROM MEMORY)
  183. git stash clear
  184.  
  185. TO SET UP YOUR REPOSITORY FOR SHARING ON A CENTRAL SERVER
  186. Copy up your repository. e.g.:
  187.  
  188. scp -r my_project deploy@yourbox.com:my_project
  189.  
  190. Move your files on the remote server to /var/git/my_project
  191. For security make the owner of this project git
  192. On the repository server:
  193.  
  194. sudo chown -R git:git my_project
  195.  
  196. Then (for security) restrict the �deploy� user to doing git-related things in /etc/passwd with a git-shell.
  197.  
  198. TO CHECK OUT THE GIT REPOSITORY TO YOUR LOCALHOST. ON YOUR LOCAL HOST DO THIS:
  199. git clone git@yourbox.com:/var/git/my_project
  200. TO SEE SOME INFO ABOUT THE REPOSITORY THAT WILL TELL YOU WHICH REPOSITORY IS THE MASTER AND WHICH IS THE SLAVE:
  201. cat .git/config
  202.  
  203. By virtue of having cloned the remote repository, your local repository becomes the slave and will track and synchronize with the remote master branch.
  204.  
  205. TO UPDATE YOUR LOCAL BRANCH FROM THE REMOTE SERVER:
  206. git pull
  207.  
  208. TO GET A COPY OF THE ENTIRE REMOTE REPOSITORY (e.g. a repository named �laptop�) WITHOUT MERGING THEM INTO YOUR LOCAL BRANCHES USE FETCH
  209. git fetch laptop
  210.  
  211. TO MERGE TWO LOCAL BRANCHES (ie. your local xyz branch with your local master branch) USE MERGE
  212. git merge laptop/xyz
  213.  
  214. This merged the (already copied laptop repository�s xyz branch) with the current branch you�re sitting in.
  215.  
  216. TO MERGE THE REMOTE BRANCH WITH YOUR LOCAL BRANCH THAT YOU ARE SITTING IN USE PULL
  217. TO ADD LOCAL KNOWLEDGE (TO YOUR LOCAL REPOSITORY) OF A 2ND REMOTE REPOSITORY, LIKE YOUR LAPTOP
  218. git remote add laptop duo2book.local:repos/m_project
  219.  
  220. where ���laptop��" is the name of the remote repository and ���duo2book.local��� is the name of the remote machine.
  221.  
  222. TO VIEW META INFORMATION ABOUT THAT REMOTE REPOSITORY
  223. git remote show laptop
  224.  
  225. TO PUSH A COMMITTED LOCAL CHANGE OF THE xyz BRANCH TO THE REMOTE laptop BRANCH
  226. git push laptop xyz
  227.  
  228. TO CREATE A TRACKING BRANCH (A SLAVE BRANCH). Ie. to link a local branch to a remote branch:
  229. git branch --track local_branch remote_branch
  230.  
  231. NOW IF YOU�RE SITTING IN THE LOCAL TRACKING BRANCH, TO PULL YOU DON�T NEED TO SPECIFY THE REMOTE TRACKING BRANCH:
  232. git pull
  233.  
  234. Note: You can track(link) different local branches to different remote machines. For example, you can track your friend�s �upgrade� branch with your �bobs_upgrade� branch, and simultaneously you can track the origin�s �master� branch (of your main webserver) with your local �master� branch.
  235.  
  236. By convention, �origin� is the local name given to the remote centralized server which is the way SVN is usually set up on a remote server.
  237.  
  238. TO SEE WHICH LOCAL BRANCHES ARE TRACKING A REMOTE BRANCH:
  239. git remote show origin
  240.  
  241. TO WORK WITH AN SVN REPOSITORY BUT WORK WITH GIT LOCALLY:
  242. git-svn clone [http location of an svn repository]
  243.  
  244. Now you can work with the checked out directory as though it was a git repository. (cuz it is)
  245.  
  246. TO PUSH (COMMIT) CHANGES TO THE REMOTE SERVER
  247. git-svn dcommit
  248.  
  249. TO UPDATE YOUR LOCAL REPOSITORY FROM THE SVN REPOSITORY
  250. git-svn rebase
  251.  
  252. NOTE: make sure you have your perl bindings to your local svn installation.
  253.  
  254. I screwed up, how do I reset my checkout?
  255. git checkout -f

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: stayce on April 8, 2010

ADDING ==/* stayce git cheat: git st
git pull git co dev git rebase master * adding 13 git status 14 git add . 15 git commit -m "Update store feature and add top members feature" 16 git status 17 git checkout dev 18 git checkout master 19 git pull 20 git checkout dev 21 git rebase master 22 git log 23 git status 24 git checkout master 25 git merge dev 26 git log 27 git push 28 git checkout dev

You need to login to post a comment.