Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.47 KB | None | 0 0
  1. GIT BASICS
  2. LEVEL 1SAME OLD STORY
  3. !
  4. s
  5. e
  6. u
  7. s
  8. s
  9. I
  10. n
  11. o
  12. i
  13. t
  14. a
  15. r
  16. o
  17. b
  18. a
  19. l
  20. l
  21. Co
  22. LEVEL 1 — GIT BASICSVERSION CONTROL SYSTEMS
  23. Merging
  24. Ti
  25. e
  26. l
  27. u
  28. s
  29. p
  30. a
  31. C
  32. e
  33. mREPOSITORY LOCATIONS
  34. Central Repository
  35. LEVEL 1 — GIT BASICS
  36. Distributed RepositoryGit is a
  37. DISTRIBUTED VERSION CONTROL SYSTEM
  38. (DVCS)WORKING WITH GIT
  39. • Command line interface
  40. • Many GUI tools available
  41. • Official Git Site —
  42. http://git-scm.com/
  43. start here
  44. LEVEL 1 — GIT BASICSGIT HELP
  45. $ git help
  46. usage: git [--version] [--exec-path[=<path>]] [--html-path]
  47. [-p|--paginate|--no-pager] [--no-replace-objects]
  48. [--bare] [--git-dir=<path>] [--work-tree=<path>]
  49. [-c name=value] [--help]
  50. <command> [<args>]
  51. The most commonly used git commands are:
  52. add
  53. Add file contents to the index
  54. bisect
  55. Find by binary search the change that introduced a bug
  56. ...
  57. LEVEL 1 — GIT BASICSGIT HELP
  58. $ git help config
  59. GIT-CONFIG(1)
  60. Git Manual
  61. GIT-CONFIG(1)
  62. pass in any git command
  63. NAME
  64. git-config - Get and set repository or global options
  65. SYNOPSIS
  66. git config [<file-option>] [type] [-z|--null] name [value [value_regex]]
  67. git config [<file-option>] [type] --add name value
  68. ...
  69. LEVEL 1 — GIT BASICSSETTING UP GIT
  70. $ git config --global user.name "Gregg Pollack"
  71. Who gets credit for changes
  72. $ git config --global user.email gregg@codeschool.com
  73. $ git config --global color.ui true
  74. LEVEL 1 — GIT BASICS
  75. What email you use
  76. Pretty command line colorsSTARTING A REPO
  77. $ mkdir store
  78. $ cd store
  79. $ git init
  80. Initialized empty Git repository in /Users/gregg/store/.git/
  81. git metadata is stored here
  82. LEVEL 1 — GIT BASICSGIT WORK FLOW
  83. Jane creates README.txt file
  84. Starts as untracked
  85. Add file to staging area
  86. Getting ready to take a picture
  87. Commit changes
  88. A snapshot of those on the stage
  89. LEVEL 1 — GIT BASICSGIT WORK FLOW
  90. Jane creates README.txt file
  91. Add file to staging area
  92. Commit changes
  93. Jane modifies README.txt file & adds LICENSE
  94. Add both files to staging area
  95. Commit changes
  96. LEVEL 1 — GIT BASICSJane creates README.txt file
  97. $ git status
  98. To check what’s changed since last commit
  99. # On branch master
  100. #
  101. # Initial commit
  102. #
  103. # Untracked files:
  104. #
  105. (use "git add <file>..." to include in what will be committed)
  106. #
  107. Our newly created file
  108. #
  109. README.txt
  110. nothing added to commit but untracked files present (use "git add" to track)
  111. LEVEL 1 — GIT BASICSAdd file to staging area
  112. $ git add README.txt
  113. $ git status
  114. # On branch master
  115. #
  116. # Initial commit
  117. #
  118. # Changes to be committed:
  119. #
  120. (use "git rm --cached <file>..." to unstage)
  121. #
  122. #
  123. new file:
  124. README.txt
  125. #
  126. Our staged file
  127. LEVEL 1 — GIT BASICSCommit changes
  128. Commit message
  129. what work was done?
  130. timeline
  131. $ git commit -m "Create a README."
  132. [master abe28da] Create a README.
  133. 1 files changed, 1 insertions(+), 0 deletions(-)
  134. create mode 100644 README.txt
  135. master
  136. $ git status
  137. # On branch master
  138. nothing to commit (working directory clean)
  139. No new or modified files since last commit
  140. LEVEL 1 — GIT BASICSJane modifies README.txt file & adds LICENSE
  141. $ git status
  142. # On branch master
  143. # Changed but not updated:
  144. #
  145. # modified:
  146. README.txt
  147. #
  148. # Untracked files:
  149. #
  150. # LICENSE
  151. no changes added to commit
  152. LEVEL 1 — GIT BASICS
  153. masterAdd both files to staging area
  154. $ git add README.txt LICENSE
  155. OR
  156. $ git add --all
  157. Adds all new or modified files
  158. $ git status
  159. # On branch master
  160. # Changes to be committed:
  161. #
  162. # new file:
  163. LICENSE
  164. # modified:
  165. README.txt
  166. #
  167. LEVEL 1 — GIT BASICS
  168. masterCommit changes
  169. $ git commit -m "Add LICENSE and finish README."
  170. [master 1b0019c] Add LICENSE and finish README.
  171. 2 files changed, 21 insertions(+), 0 deletions(-)
  172. create mode 100644 LICENSE
  173. LEVEL 1 — GIT BASICS
  174. masterGIT TIMELINE HISTORY
  175. $ git log
  176. commit 1b0019c37e3f3724fb2e9035e6bab4d7d87bf455
  177. Author: Gregg Pollack <gregg@codeschool.com>
  178. Date:
  179. Thu Jul 5 22:31:27 2012 -0400
  180. Add LICENSE and finish README.
  181. commit 5acaf86b04aaf9cbbb8ebb9042a20a46d0b9ce76
  182. Author: Gregg Pollack <gregg@codeschool.com>
  183. Date:
  184. Thu Jul 5 22:00:46 2012 -0400
  185. Create a README.
  186. LEVEL 1 — GIT BASICS
  187. masterDIFFERENT WAYS TO ADD
  188. $ git add <list of files>
  189. Add the list of files
  190. $ git add --all Add all files
  191. $ git add *.txt Add all txt files in current directory
  192. $ git add docs/*.txt
  193. $ git add docs/
  194. $ git add "*.txt"
  195. LEVEL 1 — GIT BASICS
  196. Add all txt files in docs directory
  197. Add all files in docs directory
  198. Add all txt files in the whole project
  199. ___________________________________________________________________________________________________________________________
  200. STAGING & REMOTES
  201. LEVEL 2GIT DIFF
  202. LICENSE
  203. Copyright (c) 2012 Envy Labs LLC
  204. ...
  205. Permission is hereby granted,
  206. free of charge, to any person
  207. obtaining a copy
  208. LICENSE
  209. edit
  210. Copyright (c) 2012 Code School LLC
  211. ...
  212. Permission is hereby granted, free
  213. of charge, to any person obtaining
  214. a copy
  215. Show unstaged
  216. $ git diff
  217. diff --git a/LICENSE b/LICENSE
  218. index 7e4922d..442669e 100644
  219. --- a/LICENSE
  220. +++ b/LICENSE
  221. @@ -1,4 +1,4 @@
  222. -Copyright (c) 2012 Envy Labs LLC
  223. +Copyright (c) 2012 Code School LLC
  224. differences since last commit
  225. Line removed
  226. Line addedVIEWING STAGED DIFFERENCES
  227. $ git add LICENSE
  228. $ git diff
  229. No differences, since all changes are staged
  230. $ git diff --staged
  231. View staged differences
  232. diff --git a/LICENSE b/LICENSE
  233. index 7e4922d..442669e 100644
  234. --- a/LICENSE
  235. +++ b/LICENSE
  236. @@ -1,4 +1,4 @@
  237. -Copyright (c) 2012 Envy Labs LLC
  238. +Copyright (c) 2012 Code School LLC
  239. LEVEL 2 — STAGING & REMOTESUNSTAGING FILES
  240. $
  241. #
  242. #
  243. #
  244. #
  245. #
  246. #
  247. $
  248. Unstage Tip
  249. git status
  250. On branch master
  251. Changes to be committed:
  252. (use "git reset HEAD <file>..." to unstage)
  253. modified:
  254. LICENSE
  255. Refers to last commit
  256. git reset HEAD LICENSE
  257. Unstaged changes after reset:
  258. M LICENSE
  259. LEVEL 2 — STAGING & REMOTES
  260. master
  261. HEADDISCARD CHANGES
  262. $ git status
  263. # On branch master
  264. # Changed but not updated:
  265. #
  266. (use "git add <file>..." to update what will be committed)
  267. #
  268. (use "git checkout -- <file>..." to discard changes in working directory)
  269. #
  270. # modified:
  271. LICENSE
  272. #
  273. $ git checkout -- LICENSE
  274. $ git status
  275. Blow away all changes
  276. since last commit
  277. nothing to commit (working directory clean)
  278. LEVEL 2 — STAGING & REMOTESSKIP STAGING AND COMMIT
  279. Readme.txt
  280. here is my readme
  281. Readme.txt
  282. edit
  283. and now I can sleep
  284. here is my readme
  285. the cake is a lie
  286. Add changes from all tracked files
  287. $ git commit -a -m "Modify readme"
  288. [master d00fefc] Modify readme
  289. 1 files changed, 1 insertions(+), 1 deletions(-)
  290. Doesn’t add new (untracked) files
  291. LEVEL 2 — STAGING & REMOTES
  292. master
  293. HEADUNDOING A COMMIT
  294. Whoops, we forgot something on that commit.
  295. Reset into staging
  296. $ git reset --soft HEAD^
  297. $
  298. #
  299. #
  300. #
  301. #
  302. #
  303. #
  304. git status
  305. On branch master
  306. Changes to be committed:
  307. (use "git reset HEAD <file>..." to unstage)
  308. Move to commit before ‘HEAD’
  309. modified:
  310. README.txt
  311. Now I can make changes, and re-commit
  312. LEVEL 2 — STAGING & REMOTES
  313. master
  314. HEADADDING TO A COMMIT
  315. Maybe we forgot to add a file
  316. Add to the last commit
  317. $ git add todo.txt
  318. master
  319. New commit message
  320. $ git commit --amend -m "Modify readme & add todo.txt."
  321. [master fe98ef9] Modify readme and add todo.txt.
  322. 2 files changed, 2 insertions(+), 1 deletions(-)
  323. create mode 100644 todo.txt
  324. Whatever has been staged is added to last commit
  325. LEVEL 2 — STAGING & REMOTES
  326. HEADUSEFUL COMMANDS
  327. $ git reset --soft HEAD^
  328. Undo last commit, put changes into staging
  329. $ git commit --amend -m "New Message"
  330. $ git reset --hard HEAD^
  331. $ git reset --hard HEAD^^
  332. LEVEL 2 — STAGING & REMOTES
  333. Change the last commit
  334. Undo last commit and all changes
  335. Undo last 2 commits and all changesHOW TO SHARE?
  336. Remote Repository
  337. push
  338. master
  339. pull
  340. pull
  341. “git remote” command
  342. Git doesn’t take care of access control
  343. LEVEL 2 — STAGING & REMOTESREMOTE REPOSITORY HOSTING
  344. Hosted Self Managed
  345. • GitHub • Gitosis
  346. • BitBucket • Gitorious
  347. push
  348. master
  349. LEVEL 2 — STAGING & REMOTESLEVEL 2 - STAGING & REMOTESLEVEL 2 - STAGING & REMOTESADDING A REMOTE
  350. $ git remote add origin https://github.com/Gregg/git-real.git
  351. New remote
  352. our name for this remote
  353. show remote repositories
  354. $ git remote -v
  355. origin https://github.com/Gregg/git-real.git (fetch)
  356. origin https://github.com/Gregg/git-real.git (push)
  357. LEVEL 2 — STAGING & REMOTES
  358. address
  359. originPU SHING TO R EMOTE
  360. remote repository name
  361. local branch to push
  362. $ git push -u origin master
  363. push
  364. Username for 'https://github.com': Gregg
  365. Password for 'https://Gregg@github.com':
  366. Counting objects: 11, done.
  367. Delta compression using up to 4 threads.
  368. Compressing objects: 100% (6/6), done.
  369. Writing objects: 100% (11/11), 1.50 KiB, done.
  370. Total 11 (delta 0), reused 0 (delta 0)
  371. To https://github.com/Gregg/git-real.git
  372. * [new branch]
  373. master -> master
  374. Password caching
  375. master
  376. https://help.github.com/articles/set-up-git
  377. originLEVEL 2 - STAGING & REMOTESSame information from “git log”
  378. LEVEL 2 - STAGING & REMOTESPU LLING FROM REMOTE
  379. To pull changes down from the remote
  380. $ git pull
  381. remote: Counting objects: 5, done.
  382. remote: Compressing objects: 100% (1/1), done.
  383. remote: Total 3 (delta 1), reused 3 (delta 1)
  384. It’s
  385. Unpacking objects: 100% (3/3), done.
  386. From https://github.com/Gregg/git-real
  387. fe98ef9..4e67ded master
  388. -> origin/master
  389. Updating fe98ef9..4e67ded
  390. Fast-forward
  391. todo.txt | 1 +
  392. 1 file changed, 1 insertion(+)
  393. LEVEL 2 — STAGING & REMOTES
  394. pull
  395. origin
  396. good
  397. n
  398. e
  399. t
  400. f
  401. o
  402. s
  403. i
  404. h
  405. t
  406. o
  407. to dHAVING MULTIPLE REMOTES
  408. production
  409. origin
  410. test
  411. LEVEL 2 — STAGING & REMOTESWORKING WITH REMOTES
  412. To add new remotes
  413. $ git remote add <name> <address>
  414. To remove remotes
  415. $ git remote rm <name>
  416. To push to remotes
  417. $ git push -u <name> <branch>
  418. usually master
  419. LEVEL 2 — STAGING & REMOTESUSEFUL COMMANDS
  420. $ git reset --soft HEAD^
  421. Don’t do these after
  422. $ git commit --amend -m "New Message"
  423. $ git reset --hard HEAD^
  424. $ git reset --hard HEAD^^
  425. LEVEL 2 — STAGING & REMOTES
  426. you push
  427. ____________________________________________________________________________________________________________________________________________________
  428. CLONING & BRANCHING
  429. LEVEL 3COLLABORATING
  430. “I want a copy”
  431. “Clone the repo!”
  432. g
  433. g
  434. e
  435. Gr
  436. Jane
  437. push
  438. local repo
  439. github
  440. How do we start collaborating?
  441. LEVEL 3 — CLONING & BRANCHING
  442. ?FINDING THE REPO URL
  443. URL of the remote repository
  444. LEVEL 3 — CLONING & BRANCHINGFINDING THE REPO URL
  445. URL of the remote repository
  446. LEVEL 3 — CLONING & BRANCHINGCLONING A REPOSITORY
  447. $ git clone https://github.com/codeschool/git-real.git
  448. Cloning into 'git-real'...
  449. URL of the remote repository
  450. $ git clone https://github.com/codeschool/git-real.git git-demo
  451. Cloning into 'git-demo'...
  452. local folder name
  453. LEVEL 3 — CLONING & BRANCHINGGIT CLONE
  454. 1 - Downloads the entire repository into a new git-real directory.
  455. 2 - Adds the ‘origin’ remote, pointing it to the clone URL.
  456. $ git remote -v
  457. origin
  458. origin
  459. https://github.com/codeschool/git-real.git (fetch)
  460. https://github.com/codeschool/git-real.git (push)
  461. 3 - Checks out initial branch (likely master).
  462. sets the head
  463. LEVEL 3 — CLONING & BRANCHING
  464. master
  465. HEADBRANCHING OUT
  466. Need to work on a feature that will take some time?
  467. Time to branch out.
  468. $ git branch cat
  469. Jane
  470. cat
  471. branch created from master
  472. HEAD
  473. $ git branch
  474. cat
  475. * master
  476. HEAD still on master
  477. LEVEL 3 — CLONING & BRANCHING
  478. masterSWITCHING TO A BRANCH
  479. Time to jump on that new 'cat' branch.
  480. Jane
  481. cat
  482. $ git checkout cat
  483. Switched to branch 'cat'
  484. HEAD
  485. HEAD is now on ‘cat’
  486. master
  487. LEVEL 3 — CLONING & BRANCHINGWORKING ON A BRANCH
  488. $ echo "Schrödinger" > cat.txt
  489. $ git add cat.txt
  490. $ git commit -m "Create quantum cat."
  491. [cat ab48a3f] Create quantum cat.
  492. 1 file changed, 1 insertion(+)
  493. create mode 100644 cat.txt
  494. cat
  495. HEAD
  496. committed to the
  497. “cat” branch
  498. master
  499. LEVEL 3 — CLONING & BRANCHINGWORKING ON A BRANCH
  500. $ ls
  501. README.txt cat.txt
  502. see the cat?
  503. cat
  504. HEAD
  505. master
  506. LEVEL 3 — CLONING & BRANCHINGBACK TO MASTER
  507. $ git checkout master
  508. Switched to branch 'master'
  509. $ ls
  510. README.txt
  511. cat.txt is gone!
  512. and we’re back on master
  513. $ git log
  514. commit 1191ceb7252c9d4b1e05c9969a55766a8adfce3b
  515. Author: Gregg <gregg@codeschool.com>
  516. Date:
  517. Wed Jun 27 23:11:20 2012 -0700
  518. Add README.
  519. nothing in the log either
  520. LEVEL 3 — CLONING & BRANCHING
  521. cat
  522. HEAD
  523. masterBACK TO CAT
  524. $ git checkout cat
  525. Switched to branch 'cat'
  526. $ ls
  527. README.txt cat.txt
  528. cat
  529. phew, still here
  530. HEAD
  531. master
  532. LEVEL 3 — CLONING & BRANCHINGTIME TO MERGE
  533. Done with that feature branch? Time to merge it into 'master '.
  534. $ git checkout master
  535. Switched to branch 'master'
  536. $ ls
  537. README.txt
  538. HEAD
  539. no cat, as expected
  540. $ git merge cat
  541. Updating 1191ceb..ab48a3f
  542. Fast-forward
  543. cat.txt |
  544. 1 +
  545. 1 file changed, 1 insertion(+)
  546. create mode 100644 cat.txt
  547. what’s that?
  548. merge brings one branch’s changes into another
  549. master
  550. catFAST-FORWARD TO THE FUTURE
  551. Conditions for a fast-forward merge
  552. master
  553. HEAD
  554. cat
  555. nothing new
  556. LEVEL 3 — CLONING & BRANCHING
  557. something newBRANCH CLEAN UP
  558. When you’re done with a branch, you can safely remove it.
  559. $ git branch -d cat
  560. Deleted branch cat (was 957dbff).
  561. LEVEL 3 — CLONING & BRANCHING
  562. master
  563. HEAD
  564. catNON-FAST-FORWARD
  565. Let’s work on a new admin feature.
  566. h
  567. c
  568. n
  569. a
  570. r
  571. b
  572. t
  573. u
  574. o
  575. s
  576. k
  577. c
  578. e
  579. h
  580. c
  581. d
  582. n
  583. a
  584. s
  585. e
  586. creat
  587. $ git checkout -b admin
  588. Switched to a new branch 'admin'
  589. ...
  590. $ git add admin/dashboard.html
  591. $ git commit -m 'Add dashboard'
  592. ...
  593. $ git add admin/users.html
  594. $ git commit -m 'Add user admin'
  595. “Please fix the bugs on master.”
  596. LEVEL 3 — CLONING & BRANCHING
  597. master
  598. admin
  599. HEADBUG FI XING ON MASTER
  600. Time to put out the fire. We’ll get back to that admin branch later.
  601. $ git checkout master
  602. Switched to branch 'master'
  603. $ git branch
  604. admin
  605. * master
  606. $ git pull
  607. ...
  608. $ git add store.rb
  609. $ git commit -m 'Fix store bug'
  610. ...
  611. $ git add product.rb
  612. $ git commit -m 'Fix product'
  613. ...
  614. $ git push
  615. master
  616. admin
  617. HEAD
  618. HEADBACK TO OUR BRANCH
  619. $ git checkout admin
  620. Switched to branch 'admin'
  621. ...
  622. master
  623. admin
  624. When ready to bring in changes
  625. $ git checkout master
  626. Switched to branch 'master'
  627. $ git merge admin
  628. LEVEL 3 — CLONING & BRANCHING
  629. HEAD
  630. HEADAND SUDDENLY...
  631. Git uses Vi if no default editor is set to edit commit messages.
  632. 1
  633. 2
  634. 3
  635. 4
  636. 5
  637. 6
  638. 7
  639. Merge branch 'admin'
  640. #
  641. #
  642. #
  643. #
  644. #
  645. :wq
  646. DON
  647. ’T P
  648. ANI
  649. Please enter a commit message to explain why this merge is necessary,
  650. especially if it merges an updated upstream into a topic branch.
  651. Lines starting with '#' will be ignored, and an empty message aborts
  652. the commit.
  653. + hit Enter to write (save) & quit
  654. Vi commands
  655. j down k up ESC leave mode :wq save & quit
  656. h left l right i insert mode :q! cancel & quit
  657. CRECURSIVE MERGING
  658. Git can’t fast-forward since changes were made in both branches.
  659. Merge made by the 'recursive' strategy.
  660. 0 files changed
  661. create mode 100644 admin/dashboard.html
  662. create mode 100644 admin/users.html
  663. master
  664. merge commit
  665. admin
  666. A commit was created to merge the two branches.
  667. $ git log
  668. commit 19f735c3556129279bb10a0d1447dc5aba1e1fa9
  669. Merge: 5c9ed90 7980856
  670. Author: Jane <Jane@CodeSchool.com>
  671. Date:
  672. Thu Jul 12 17:51:53 2012 -0400
  673. Merge branch 'admin'
  674. 2 commits
  675. 2 commits
  676. ______________________________________________________________________________________________________________________
  677. Branching model & Commit
  678. message formatTask branches
  679. • Typically, these are called feature branches. We will use a generalized
  680. variant of the name: task branches.
  681. • A task branch should almost always be created, at least locally, before
  682. starting any changes in the code. It should be branched off of the
  683. develop branch.Before creating a task branch
  684. • It is a good habit to update your develop branch, prior to creating your task
  685. branch off of it.
  686. $ git checkout develop
  687. # switch to develop
  688. $ git pull --rebase
  689. # pull from origin/develop
  690. • Then proceed to creating and checking out your new task branch
  691. $ git checkout -b myfe develop
  692. #Switched to a branch "myfe"Keeping a branch up-to-date
  693. • Git-flow does not prescribe a way to keep feature branches up-to-
  694. date. It also assumes they are strictly local, and the original post does
  695. not discuss remote (shared) feature branches.
  696. • One could in fact, ignore this topic altogether. Just develop in isolation
  697. on the dedicated branch, while new code is being pushed to develop.
  698. And if there is nothing conflicting between develop and the task
  699. branch, the merge will pass without a hassle.Keeping a branch up-to-date
  700. • However, if conflicts emerge, they will have to be resolved on develop
  701. post-merge. Furthermore, if the branch had diverged from develop
  702. for a long time, and with many commits on both sides, the chances
  703. for numerous and more complicated conflicts are increasing.
  704. • Thus, it is advised to periodically update your longer-living task
  705. branches, to incorporate changes from develop. This should result in
  706. smaller and more manageable conflicts, which can be resolved on the
  707. task branch, before merging anything to develop.Updating a local task branch
  708. • Local longer-living task branches should be updated to include the latest
  709. content from develop, by doing the following:
  710. • Update the local develop:
  711. $ git checkout develop
  712. # switch to develop
  713. $ git pull --rebase
  714. # pull from origin/develop
  715. $ git checkout task-branch
  716. # switch to task-branch
  717. $ git rebase develop
  718. # rebase task-branch onto develop
  719. • In case of conflicts reported by the rebase, resolve those on the task
  720. branch and proceed development on it, or merge it into develop (if
  721. done).Updating a remote (shared) task branch
  722. • If a task branch gets pushed to origin (for backup purposes, or for
  723. collaboration), it should also be kept up-to-date with develop's
  724. novelties. However, our procedure to update it should be different,
  725. than the local branch update. Using rebase to update the shared task
  726. branch, would result in changing the commit history for the other
  727. users of that branch (after the rebased content is pushed). This can
  728. cause several undesired complications, so we should do the update
  729. by merging develop content into our task branch:Updating a remote (shared) task branch
  730. $ git checkout develop
  731. $ git pull --rebase
  732. $ git checkout task-branch
  733. $ git merge --no-ff develop
  734. $ git push origin task-branch
  735. # switch to develop
  736. # pull from origin/develop
  737. # switch to task-branch
  738. # merge develop into task-branch
  739. # push task-branch to originWhen should we not branch?
  740. • For trivial tasks, we can avoid the hassle of branching. Consider a
  741. direct commit & push to develop justified, only for changes that are
  742. small in size and quick to implement, such as single-commit
  743. bugfixes/mods that are very very likely to "just work".Commit message format
  744. 1. Separate subject from body with a blank line
  745. 2. Limit the subject line to 72 characters
  746. 3. Capitalize the subject line
  747. 4. Do not end the subject line with a period
  748. 5. Use imperative in the subject line
  749. 6. Wrap the body at 72 characters
  750. 7. Use the body to explain what and why vs. how
  751. Read more http://chris.beams.io/posts/git-commit/
  752. ______________________________________________________________________________________________________________
  753. COLLABORATION BASICS
  754. LEVEL 4I want a co
  755. py
  756. github
  757. push
  758. Gregg
  759. ?
  760. Jane
  761. Clone the repo
  762. $ git clone https://github.com/codeschool/git-real.git
  763. Start making changes
  764. Jane adds two filesTWO NEW FILES
  765. jane $ git status
  766. # On branch master
  767. # Untracked files:
  768. #
  769. (use "git add <file>..." to include in what will be committed)
  770. #
  771. # product.rb
  772. # store.rb
  773. nothing added to commit but untracked files present
  774. jane $ git add --all
  775. jane $ git commit -m "Add store and product models."
  776. [master 30ce481] Add product and store models.
  777. 2 files changed, 2 insertions(+)
  778. create mode 100644 product.rb
  779. create mode 100644 store.rbCOMMIT FLOW
  780. Sends her new commit
  781. jane $ git push
  782. Counting objects: 5, done.
  783. Compressing objects: 100% (2/2), done.
  784. Writing objects: 100% (4/4), 441 bytes, done.
  785. Total 4 (delta 0), reused 0 (delta 0)
  786. To https://github.com/codeschool/git-real.git
  787. 4e67ded..30ce481 master -> master
  788. github
  789. push new commits
  790. master
  791. LEVEL 4 — COLLABORATION BASICSDIFFERENT GIT COMMITS
  792. gregg $ git commit -am "Update the readme."
  793. [master c715339] Update the readme.
  794. 1 file changed, 1 insertion(+), 1 deletion(-)
  795. gregg
  796. different
  797. github
  798. same
  799. LEVEL 4 — COLLABORATION BASICS
  800. ?
  801. w
  802. o
  803. n
  804. s
  805. n
  806. e
  807. p
  808. p
  809. a
  810. h
  811. t
  812. a
  813. WhGIT PUSH REJECTED
  814. gregg $ git push
  815. Cannot write over Jane’s commit
  816. To https://github.com/codeschool/git-real.git
  817. ! [rejected]
  818. master -> master (non-fast-forward)
  819. error: failed to push some refs to 'https://github.com/codeschool/git-real.git'
  820. hint: Updates were rejected because the tip of your current branch is behind
  821. hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
  822. hint: before pushing again.
  823. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  824. $ git pull
  825. ...
  826. $ git push
  827. ...
  828. Success!
  829. LEVEL 4 — COLLABORATION BASICSUNDERSTANDING PULL
  830. $ git pull
  831. 1. Fetch (or Sync) our local repository with the remote one
  832. gregg
  833. $ git fetch
  834. github
  835. origin
  836. Fetch doesn’t actually update any of our local codeUNDERSTANDING PULL
  837. $ git pull
  838. 1. Fetch (or Sync) our local repository with the remote one
  839. gregg
  840. master
  841. origin/master
  842. $ git fetch
  843. github
  844. master
  845. 2. Merges the origin/master with master $ git merge origin/masterMERGE COMMIT
  846. $ git pull
  847. 1. Fetch (or Sync) our local repository with the remote one
  848. 2. Merges the origin/master with master $ git merge origin/master
  849. Create a new commit for this merge
  850. 1
  851. 2
  852. 3
  853. 4
  854. 5
  855. 6
  856. 7
  857. my editor
  858. Merge branch 'master' of https://github.com/codeschool/git-real
  859. #
  860. #
  861. #
  862. #
  863. #
  864. Please enter a commit message to explain why this merge is necessary,
  865. especially if it merges an updated upstream into a topic branch.
  866. Lines starting with '#' will be ignored, and an empty message aborts
  867. the commit.GIT PUSH REJECTED
  868. $ git pull
  869. remote: Counting objects: 5, done.
  870. remote: Compressing objects: 100% (2/2), done.
  871. remote: Total 4 (delta 0), reused 4 (delta 0)
  872. Unpacking objects: 100% (4/4), done.
  873. From https://github.com/codeschool/git-real
  874. 4e67ded..30ce481 master
  875. -> origin/master
  876. Merge made by the 'recursive' strategy.
  877. product.rb | 1 +
  878. store.rb
  879. | 1 +
  880. 2 files changed, 2 insertions(+)
  881. create mode 100644 product.rb
  882. create mode 100644 store.rb
  883. merge commitMERGE COMMIT
  884. $ git pull
  885. 1. Fetch (or Sync) our local repository with the remote one
  886. 2. Merges the origin/master with master
  887. master
  888. merge commit
  889. origin/master
  890. $ git fetch
  891. $ git merge origin/masterPU SHING COMMITS
  892. $ git push
  893. Update origin/master be at the same state as our local repo
  894. origin/master
  895. master
  896. merge commit
  897. githubOUR LOG
  898. gregg $ git log
  899. commit ee47baaedcd54e1957f86bda1aaa1b8a136185da
  900. Merge: 87c5243 57501d5
  901. Author: Gregg Pollack <Gregg@CodeSchool.com>
  902. The problem with pull
  903. Merge branch 'master' of https://github.com/Gregg/git-real
  904. commit 87c5243d2266f05cd9fda8b1c9137f11b3fe6f31
  905. Author: Gregg Pollack <Gregg@CodeSchool.com>
  906. Update the readme.
  907. commit 57501d595b16e2d1198a9c04c547a5b1380a6618
  908. Author: Gregg Pollack <Gregg@CodeSchool.com>
  909. Add store and product models.MERGE CONFLICTS
  910. README
  911. README
  912. Gregg
  913. here is my readme
  914. committed
  915. different
  916. same
  917. Jane
  918. the cake is telling the truth!
  919. the cake is a lie
  920. gregg
  921. here is my readme
  922. github
  923. committed & pushedMERGE CONFLICT
  924. gregg $ git pull
  925. remote: Counting objects: 5, done.
  926. remote: Compressing objects: 100% (1/1), done.
  927. remote: Total 3 (delta 1), reused 3 (delta 1)
  928. Unpacking objects: 100% (3/3), done.
  929. From https://github.com/Gregg/git-real
  930. ee47baa..4e76d35 master
  931. -> origin/master
  932. Auto-merging README.txt
  933. CONFLICT (content): Merge conflict in README.txt
  934. Automatic merge failed; fix conflicts and then commit the result.
  935. Git modified this file with the diff
  936. LEVEL 4 — COLLABORATION BASICSMERGE CONFLICT
  937. gregg $ git status
  938. # On branch master
  939. # Your branch and 'origin/master' have diverged,
  940. # and have 1 and 1 different commit each, respectively.
  941. #
  942. # Unmerged paths:
  943. #
  944. (use "git add/rm <file>..." as appropriate to mark resolution)
  945. #
  946. # both modified:
  947. README.txt
  948. #
  949. no changes added to commit (use "git add" and/or "git commit -a")
  950. Need to edit these files
  951. LEVEL 4 — COLLABORATION BASICSMERGE CONFLICT
  952. README
  953. Edit file and correct
  954. here is my readme
  955. here is my readme
  956. Our local version
  957. the
  958. Jane’s version
  959. <<<<<<< HEAD
  960. the cake is a lie.
  961. =======
  962. the cake is telling the truth!
  963. >>>>>>>
  964. 4e76d3542a7eee02ec516a47600002a90a4e4b48
  965. gregg $ git commit -a
  966. Merge commit
  967. LEVEL 4 — COLLABORATION BASICS
  968. cake is a lie.COMMIT EDITOR
  969. gregg $ git commit -a
  970. 1
  971. 2
  972. 3
  973. 4
  974. 5
  975. 6
  976. 7
  977. 8
  978. 9
  979. 10
  980. 11
  981. 12
  982. 13
  983. 14
  984. 15
  985. 16
  986. Merge commit
  987. Editor
  988. Merge branch 'master' of https://github.com/Gregg/git-real
  989. Conflicts:
  990. ▸ README.txt
  991. #
  992. # It looks like you may be committing a merge.
  993. # If this is not correct, please remove the file
  994. #▸.git/MERGE_HEAD
  995. # and try again.
  996. #
  997. #
  998. #
  999. #
  1000. #
  1001. Please enter the commit message for your changes. Lines starting
  1002. with '#' will be ignored, and an empty message aborts the commit.
  1003. On branch master
  1004. Your branch and 'origin/master' have diverged,
  1005. and have 1 and 1 different commit each, respectively.MERGE COMMIT
  1006. origin/master
  1007. master
  1008. master
  1009. Merge commit
  1010. Merge commit
  1011. origin/master
  1012. $ git pushCOLLABORATION BASICS
  1013. LEVEL 4
  1014. ________________________________________________________________________________________________________________
  1015. REMOTE BRANCHES & TAGS
  1016. LEVEL 5WHY CREATE A REMOTE BRANCH?
  1017. • When you need other people to work on your branch.
  1018. • Any branch that will last more than a day.
  1019. Gregg
  1020. LEVEL 5 — REMOTE BRANCHES AND TAGSCREATING A REMOTE BRANCH
  1021. $ git checkout -b shopping_cart
  1022. Switched to a new branch 'shopping_cart'
  1023. $ git push origin shopping_cart
  1024. Counting objects: 10, done.
  1025. Delta compression using up to 4 threads.
  1026. Compressing objects: 100% (6/6), done.
  1027. Writing objects: 100% (6/6), 619 bytes, done.
  1028. Total 6 (delta 2), reused 0 (delta 0)
  1029. To https://github.com/codeschool/git-real.git
  1030. * [new branch]
  1031. shopping_cart -> shopping_cart
  1032. Links local branch to
  1033. the remote branch
  1034. (tracking)
  1035. LEVEL 5 — REMOTE BRANCHES AND TAGSPU SHING TO THE BRANCH
  1036. $ git add cart.rb
  1037. $ git commit -a -m "Add basic cart ability."
  1038. [shopping_cart 2a0dbf9] Add basic cart ability
  1039. 1 file changed, 1 insertion(+)
  1040. create mode 100644 cart.rb
  1041. Pushed changes from branch
  1042. $ git push
  1043. Counting objects: 4, done.
  1044. Delta compression using up to 4 threads.
  1045. Compressing objects: 100% (2/2), done.
  1046. Writing objects: 100% (3/3), 302 bytes, done.
  1047. Total 3 (delta 1), reused 0 (delta 0)
  1048. To https://github.com/codeschool/git-real.git
  1049. 786d7a1..2a0dbf9 shopping_cart -> shopping_cartCREATING A BRANCH
  1050. Hey Jane, I star
  1051. ted a branch
  1052. t
  1053. u
  1054. o
  1055. t
  1056. i
  1057. k
  1058. c
  1059. e
  1060. h
  1061. c
  1062. l
  1063. l
  1064. I
  1065. ,
  1066. t
  1067. Swee
  1068. LEVEL 5 — REMOTE BRANCHES AND TAGSPU LLING NEW BRANCHES
  1069. $ git pull
  1070. remote: Counting objects: 13, done.
  1071. remote: Compressing objects: 100% (6/6), done.
  1072. remote: Total 9 (delta 3), reused 8 (delta 2)
  1073. Unpacking objects: 100% (9/9), done.
  1074. From https://github.com/Gregg/git-real
  1075. 4e76d35..786d7a1 master
  1076. -> origin/master
  1077. * [new branch]
  1078. shopping_cart -> origin/shopping_cart
  1079. Updating 4e76d35..786d7a1
  1080. Fast-forward
  1081. README.txt | 2 +-
  1082. 1 file changed, 1 insertion(+), 1 deletion(-)
  1083. LEVEL 5 — REMOTE BRANCHES AND TAGS
  1084. remote branchPU LLING NEW BRANCHES
  1085. $ git branch
  1086. * master
  1087. $ git branch -r
  1088. origin/master
  1089. origin/shopping_cart
  1090. list all remote branches
  1091. $ git checkout shopping_cart
  1092. Branch shopping_cart set up to track remote branch shopping_cart from origin.
  1093. Switched to a new branch 'shopping_cart'
  1094. $ git branch
  1095. master
  1096. * shopping_cart
  1097. !
  1098. h
  1099. s
  1100. u
  1101. p
  1102. d
  1103. n
  1104. a
  1105. e
  1106. t
  1107. u
  1108. b
  1109. i
  1110. r
  1111. t
  1112. n
  1113. o
  1114. c
  1115. n
  1116. a
  1117. c
  1118. e
  1119. w
  1120. Now
  1121. LEVEL 5 — REMOTE BRANCHES AND TAGSREMOTE SHOW
  1122. $ git remote show origin
  1123. * remote origin
  1124. Fetch URL: https://github.com/Gregg/git-real.git
  1125. Push URL: https://github.com/Gregg/git-real.git
  1126. HEAD branch: master
  1127. Remote branches:
  1128. master
  1129. tracked
  1130. shopping_cart tracked
  1131. Local branches configured for 'git pull':
  1132. master
  1133. merges with remote master
  1134. shopping_cart merges with remote shopping_cart
  1135. Local refs configured for 'git push':
  1136. master
  1137. pushes to master
  1138. (up to date)
  1139. shopping_cart pushes to shopping_cart (local out of date)REMOVING A BRANCH
  1140. $ git push origin :shopping_cart
  1141. Deletes remote branch
  1142. To https://github.com/codeschool/git-real.git
  1143. - [deleted]
  1144. shopping_cart
  1145. $ git branch -d shopping_cart
  1146. Must delete local branch manua
  1147. lly
  1148. error: The branch 'shopping_cart' is not fully merged.
  1149. If you are sure you want to delete it, run 'git branch -D shopping_cart'.
  1150. $ git branch -D shopping_cart
  1151. Deleted branch shopping_cart (was ea0a1b9).
  1152. LEVEL 5 — REMOTE BRANCHES AND TAGSWHAT ABOUT GREGG?
  1153. Jane
  1154. Gregg
  1155. LEVEL 5 — REMOTE BRANCHES AND TAGSON DELETED REMOTE BRANCH
  1156. $ git commit -m -a "Add ability to pay."
  1157. [shopping_cart 9851887] Add ability to pay.
  1158. 1 file changed, 1 insertion(+), 1 deletion(-)
  1159. $ git push
  1160. No remote to push to (it’s jus
  1161. Everything up-to-date
  1162. Gregg
  1163. t a local branch now)
  1164. $ git remote show origin
  1165. Remote branches:
  1166. master
  1167. tracked
  1168. refs/remotes/origin/shopping_cart stale (use 'git remote prune' to remove)
  1169. $ git remote prune origin
  1170. To clean up deleted remote br
  1171. anches
  1172. Pruning origin
  1173. URL: https://github.com/codeschool/git-real.git
  1174. * [pruned] origin/shopping_cartREMOTE BRANCH NAMES
  1175. Heroku deploys only master bra
  1176. $ git branch
  1177. * staging
  1178. master
  1179. $ git push heroku-staging staging
  1180. Would not work, would push to staging
  1181. local:remote
  1182. $ git push heroku-staging staging:master
  1183. Will push and deploy staging on heroku
  1184. LEVEL 5 — REMOTE BRANCHES AND TAGS
  1185. nc h
  1186. heroku-stagingTAGGING
  1187. A tag is a reference to a commit (used mostly for release versioning)
  1188. $ git tag
  1189. v0.0.1
  1190. v0.0.2
  1191. list all tags
  1192. $ git checkout v0.0.1
  1193. it
  1194. m
  1195. m
  1196. o
  1197. c
  1198. t
  1199. a
  1200. e
  1201. d
  1202. o
  1203. c
  1204. t
  1205. u
  1206. o
  1207. check
  1208. Text
  1209. To add a new tag
  1210. $ git tag -a v0.0.3 -m "version 0.0.3"
  1211. To push new tags
  1212. $ git push --tags
  1213. LEVEL 5 — REMOTE BRANCHES AND TAGSREMOTE BRANCHES & TAGS
  1214. LEVEL 5
  1215. _________________________________________________________________________________________________________________________
  1216. REBASE BELONG TO US
  1217. LEVEL 6MERGE COMMITS ARE BAD
  1218. Merge branch 'cats'
  1219. origin/master
  1220. master
  1221. Add Cats.
  1222. merge commit
  1223. Merge branch 'master' of http...
  1224. Update the Readme.
  1225. Add product and store models.
  1226. M
  1227. s
  1228. s
  1229. e
  1230. l
  1231. e
  1232. s
  1233. u
  1234. l
  1235. e
  1236. e
  1237. f
  1238. s
  1239. t
  1240. i
  1241. m
  1242. m
  1243. o
  1244. c
  1245. e
  1246. g
  1247. r
  1248. e
  1249. LEVEL 6 — REBASE BELONG TO USDIFFERENT GIT COMMITS
  1250. gregg $ git commit -am "Update the readme."
  1251. [master c715339] Update the readme.
  1252. 1 file changed, 1 insertion(+), 1 deletion(-)
  1253. gregg
  1254. different
  1255. github
  1256. same
  1257. LEVEL 6 — REBASE BELONG TO US
  1258. t
  1259. i
  1260. m
  1261. m
  1262. o
  1263. c
  1264. s
  1265. Jane’GIT PUSH REJECTED
  1266. gregg $ git push
  1267. Cannot write over Jane’s commit
  1268. To https://github.com/codeschool/git-real.git
  1269. ! [rejected]
  1270. master -> master (non-fast-forward)
  1271. error: failed to push some refs to 'https://github.com/codeschool/git-real.git'
  1272. hint: Updates were rejected because the tip of your current branch is behind
  1273. hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
  1274. hint: before pushing again.
  1275. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  1276. $ git pull
  1277. ...
  1278. $ git push
  1279. !
  1280. e
  1281. p
  1282. o
  1283. N
  1284. ...
  1285. LEVEL 6 — REBASE BELONG TO USFETCH
  1286. gregg $ git fetch
  1287. remote: Counting objects: 5, done.
  1288. remote: Compressing objects: 100% (2/2), done.
  1289. remote: Total 4 (delta 0), reused 4 (delta 0)
  1290. Unpacking objects: 100% (4/4), done.
  1291. From https://github.com/codeschool/git-real
  1292. f35f2f1..71a4650 master
  1293. -> origin/master
  1294. gregg
  1295. github
  1296. Syncs
  1297. but doesn’t merge
  1298. LEVEL 6 — REBASE BELONG TO US
  1299. master
  1300. origin/masterREBASE
  1301. gregg $ git rebase
  1302. 1. Move all changes to master which are not in origin/master to a temporary area.
  1303. temp
  1304. master
  1305. origin/master
  1306. LEVEL 6 — REBASE BELONG TO USREBASE
  1307. gregg $ git rebase
  1308. 1. Move all changes to master which are not in origin/master to a temporary area.
  1309. 2. Run all origin/master commits.
  1310. temp
  1311. master
  1312. origin/master
  1313. 3. Run all commits in the temporary area, one at a time.
  1314. LEVEL 6 — REBASE BELONG TO USREBASE
  1315. gregg $ git rebase
  1316. 1. Move all changes to master which are not in origin/master to a temporary area.
  1317. 2. Run all origin/master commits.
  1318. 3. Run all commits in the temporary area, one at a time.
  1319. master
  1320. Update the Readme.
  1321. No M
  1322. erge
  1323. Add product and store models.
  1324. Comm
  1325. it!LOCAL BRANCH REBASE
  1326. $ git checkout admin
  1327. Switched to branch 'admin'
  1328. $ git rebase master
  1329. ...
  1330. master
  1331. admin
  1332. Rebase
  1333. master
  1334. adminI F AL L GOES WELL, MERGE MAS TER
  1335. $ git checkout master
  1336. Switched to branch 'master'
  1337. $ git merge admin
  1338. ...
  1339. master
  1340. adminWHAT ABOUT CONFLICTS
  1341. gregg
  1342. github
  1343. !
  1344. e
  1345. l
  1346. i
  1347. f
  1348. e
  1349. m
  1350. sa
  1351. Add shopping cart.
  1352. d
  1353. e
  1354. t
  1355. i
  1356. d
  1357. E
  1358. Add lie to readme.
  1359. same
  1360. LEVEL 6 — REBASE BELONG TO US
  1361. Add truth to readme.
  1362. Add product and store models.FETCH
  1363. gregg $ git fetch
  1364. master
  1365. origin/master
  1366. Add shopping cart. Add truth to readme.
  1367. Add lie to readme. Add product and store models.
  1368. LEVEL 6 — REBASE BELONG TO USREBASE
  1369. gregg $ git rebase
  1370. 1. Move all changes to master which are not in origin/master to a temporary area
  1371. origin/master
  1372. temp
  1373. Add truth to readme.
  1374. Add product and store models.
  1375. masterREBASE
  1376. gregg $ git rebase
  1377. 2. Run all origin/master commits.
  1378. temp
  1379. master
  1380. Add shopping cart.
  1381. Add truth to readme.
  1382. Add product and store models.
  1383. Add lie to readme.
  1384. 3. Run all commits in the temporary area, one at a time.REBASE CONFLICT
  1385. gregg $ git rebase
  1386. First, rewinding head to replay your work on top of it...
  1387. Applying: Add lie to readme.
  1388. Using index info to reconstruct a base tree...
  1389. M README.txt
  1390. <stdin>:13: trailing whitespace.
  1391. the cake is a lie, and I am your father!
  1392. warning: 1 line adds whitespace errors.
  1393. Falling back to patching base and 3-way merge...
  1394. Auto-merging README.txt
  1395. CONFLICT (content): Merge conflict in README.txt
  1396. Failed to merge in the changes.
  1397. Patch failed at 0001 Add lie to readme.
  1398. master
  1399. CONFLICT
  1400. When you have resolved this problem run "git rebase --continue".
  1401. If you would prefer to skip this patch, instead run "git rebase --skip".
  1402. To check out the original branch and stop rebasing run "git rebase --abort".REBASE CONFLICT
  1403. gregg $ git status
  1404. # Not currently on any branch.
  1405. # Unmerged paths:
  1406. #
  1407. (use "git reset HEAD <file>..." to unstage)
  1408. #
  1409. (use "git add/rm <file>..." as appropriate to mark resolution)
  1410. #
  1411. # both modified:
  1412. README.txt
  1413. #
  1414. no changes added to commit (use "git add" and/or "git commit -a")
  1415. Edit the README.txt
  1416. gregg $ git add README.txt
  1417. gregg $ git rebase --continue
  1418. Applying: Add lie to readme.
  1419. Applying: Add shopping cart
  1420. gregg $
  1421. masterREBASED LOG
  1422. master
  1423. Add shopping cart.
  1424. Add lie to readme.
  1425. Add truth to readme.
  1426. Add product and store models.REBASE BELONG TO US
  1427. LEVEL 6
  1428. _______________________________________________________________________________________________________________________
  1429. git workflows
  1430. Tomche Delev M.Sc.Workflow
  1431. Guidelines rather than concrete rules
  1432. The way you use and incorporate
  1433. some technology in the daily work
  1434. process.Centralized
  1435. workflowHow it works?
  1436. ● Central repository to serve as the single point-of-entry for
  1437. all changes to the project (master <-> trunk)
  1438. ● Developers clone the central repository
  1439. ● Everything is stored locally isolated from the central
  1440. repositoryPush changesManaging conflictsExamplessh user@host git init --bare /path/to/repo.git
  1441. Someone initializes empty repositorygit clone ssh://user@host/path/to/repo.git
  1442. Everybody clones the central repositorygit status # View the state of the repo
  1443. git add <some-file> # Stage a file
  1444. git commit # Commit a file</some-file>
  1445. John works on his featuregit status # View the state of the repo
  1446. git add <some-file> # Stage a file
  1447. git commit # Commit a file</some-file>
  1448. Mary works on her featuregit push origin master
  1449. John publishes his featureerror: failed to push some refs to '/path/to/repo.git'
  1450. hint: Updates were rejected because the tip of your
  1451. current branch is behind
  1452. hint: its remote counterpart. Merge the remote changes (e.
  1453. g. 'git pull')
  1454. hint: before pushing again.
  1455. hint: See the 'Note about fast-forwards' in 'git push --
  1456. help' for details.
  1457. git push origin master
  1458. Mary tries to publish her featuregit pull --rebase origin master
  1459. Mary rebases on top of John’s commit(s)Mary rebases on top of John’s commit(s)CONFLICT (content): Merge conflict in <some-file>
  1460. Mary resolves a merge conflictMary resolves a merge conflict#
  1461. #
  1462. #
  1463. #
  1464. #
  1465. Unmerged paths:
  1466. (use "git reset HEAD <some-file>..." to unstage)
  1467. (use "git add/rm <some-file>..." as appropriate to mark resolution)
  1468. both modified: <some-file>
  1469. git add <some-file>
  1470. git rebase --continue
  1471. git rebase --abort
  1472. Mary resolves a merge conflictgit push origin master
  1473. Mary successfully publishes her featureFeature Branch
  1474. WorkflowBasic ideas
  1475. ● The core idea behind the Feature Branch Workflow is that
  1476. all feature development should take place in a dedicated
  1477. branch instead of the master branch.
  1478. ● Pull requests (easy way for your team to comment on each
  1479. other’s work)How it works?
  1480. ● Still uses a central repository, and master still represents
  1481. the official project history
  1482. ● Developers create a new branch every time they start work
  1483. on a new feature (feature branch)
  1484. animated-menu-items, issue-#1662
  1485. Feature branches can (and should) be pushed to the
  1486. central repositoryPull Requests
  1487. ● Discuss changes before merge or ask for help
  1488. Once a pull request is accepted, the actual act of
  1489. publishing a feature is much the same as in the Centralized
  1490. WorkflowExamplegit checkout -b marys-feature master
  1491. git status
  1492. git add <some-file>
  1493. git commit
  1494. Mary begins a new featuregit push -u origin marys-feature
  1495. Mary goes to lunchgit push
  1496. Mary finishes her featureBill receives the pull requestMary makes the changesgit
  1497. git
  1498. git
  1499. git
  1500. checkout master
  1501. pull
  1502. pull origin marys-feature
  1503. push
  1504. Mary publishes her featureMeanwhile, John is doing the exact same thingGitflow
  1505. Workflowhttp://nvie.com/posts/a-successful-git-branching-model/How it works?
  1506. ● The only difference...
  1507. ● It assigns very specific roles to different branches and
  1508. defines how and when they should interact.
  1509. ● In addition to feature branches, it uses individual branches
  1510. for preparing, maintaining, and recording releasesHistorical BranchesFeature BranchesRelease BranchesMaintenance BranchesExamplegit branch develop
  1511. git push -u origin develop
  1512. git clone ssh://user@host/path/to/repo.git
  1513. git checkout -b develop origin/develop
  1514. Create a develop branchgit checkout -b some-feature develop
  1515. git status
  1516. git add <some-file>
  1517. git commit
  1518. Mary and John begin new featuresgit
  1519. git
  1520. git
  1521. git
  1522. git
  1523. pull origin develop
  1524. checkout develop
  1525. merge some-feature
  1526. push
  1527. branch -d some-feature
  1528. Mary finishes her featuregit checkout -b release-0.1 develop
  1529. Mary begins to prepare a releasegit
  1530. git
  1531. git
  1532. git
  1533. git
  1534. git
  1535. git
  1536. checkout master
  1537. merge release-0.1
  1538. push
  1539. checkout develop
  1540. merge release-0.1
  1541. push
  1542. branch -d release-0.1
  1543. git tag -a 0.1 -m "Initial public release" master
  1544. git push --tags
  1545. Mary finishes the releasegit checkout -b issue-#001 master
  1546. # Fix the bug
  1547. git checkout master
  1548. git merge issue-#001
  1549. git push
  1550. git
  1551. git
  1552. git
  1553. git
  1554. checkout develop
  1555. merge issue-#001
  1556. push
  1557. branch -d issue-#001
  1558. End-user discovers a bugForking
  1559. workflowHow it works?
  1560. ● fork the official repository to create a copy of it on the server
  1561. ● git clone to get a copy of it onto local machine
  1562. ● When ready to publish a local commit, push the commit to own public
  1563. repository - not the official one
  1564. ● File a pull request with the main repository, which lets the project
  1565. maintainer know that an update is ready to be integratedHow it works?
  1566. ● The maintainer pulls the contributor’s changes into their local
  1567. repository, checks to make sure it doesn’t break the project, merges it
  1568. into his local master branch
  1569. ● Then pushes the master branch to the official repository on the
  1570. server.
  1571. ● The contribution is now part of the project, and other developers
  1572. should pull from the official repository to synchronize their local
  1573. repositoriesThe Official Repository?
  1574. Branching in the Forking WorkflowExamplessh user@host
  1575. git init --bare /path/to/repo.git
  1576. The project maintainer initializes the official repositoryDevelopers fork the official repositorygit clone https://user@bitbucket.org/user/repo.git
  1577. git remote add upstream https://bitbucket.org/maintainer/repo
  1578. git remote add upstream https://user@bitbucket.org/maintainer/repo.git
  1579. Developers clone their forked repositoriesgit checkout -b some-feature
  1580. # Edit some code
  1581. git commit -a -m "Add first draft of some feature"
  1582. git pull upstream master
  1583. Developers work on their featuresgit push origin feature-branch
  1584. Developers publish their featuresgit fetch https://bitbucket.org/user/repo feature-branch
  1585. # Inspect the changes
  1586. git checkout master
  1587. git merge FETCH_HEAD
  1588. git push origin master
  1589. The project maintainer integrates their featuresgit pull upstream master
  1590. Developers synchronize with the official repositoryThe End
  1591. https://twitter.com/joserobleda/status/707846636345683968References:
  1592. Questions?
  1593. Thank you for your attention!
  1594. https://www.atlassian.com/git/tutorials/comparing-workflows
  1595. http://nvie.com/posts/a-successful-git-branching-model/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement