[MacPorts] WorkingWithGit modified

MacPorts noreply at macports.org
Mon Jan 30 22:02:01 UTC 2017


Page "WorkingWithGit" was changed by ctreleaven
Diff URL: <https://trac.macports.org/wiki/WorkingWithGit?action=diff&version=74>
Revision 74
Comment: Preliminary notes about using branches
Changes:
-------8<------8<------8<------8<------8<------8<------8<------8<--------
Index: WorkingWithGit
=========================================================================
--- WorkingWithGit (version: 73)
+++ WorkingWithGit (version: 74)
@@ -138,6 +138,66 @@
  - To throw away all changes that you have locally committed but not yet pushed, use `git reset --hard origin/master`. '''You will lose all your uncommitted and committed modifications.''' If that is not what you want, Git provides a variety of tools that allow you to change commits that you have not pushed yet (and theoretically also commits that have already been pushed, which will prevent you from pushing any changes again). Since this is an advanced topic it will not be covered here. As a pointer for further research, look for `git commit --amend` to change the topmost commit and `git rebase --interactive`, the so-called "interactive rebase", to change older commits.
 
 
+=== Using a branch for development === #branch
+
+Commonly, you'd use a local branch for development if you want this work isolated, such as when you are making experimental changes or it may take some time complete the work.
+
+The life cycle for a branch, say "foobar", might look like this:
+{{{
+git branch foobar     # creates a local branch
+git checkout foobar
+}}}
+
+- lots of edits and testing
+
+{{{
+git commit -m "blah blah"
+}}}
+
+
+- more testing and corrections
+
+{{{
+git commit -a --amend -m "revised blah blah"
+}}}
+
+
+- throughout the process, you can 'git checkout master' / 'git checkout foobar' to switch in and out of the branch.
+
+- if there are upstream changes that need to be reflected in your branch...
+
+{{{
+git branch --set-upstream-to=origin/master foobar
+git pull --rebase
+}}}
+
+
+- finally, work is done.  Now merge the changes into your local master...
+
+{{{
+git checkout master
+git merge --ff-only foobar
+}}}
+
+- check that only your expected commits are about to be pushed
+
+{{{
+git log origin/master..foobar
+}}}
+
+
+- normal steps to push
+
+{{{
+git pull --rebase  && git push origin master
+}}}
+
+
+- if we're done with the branch, nuke it
+
+{{{
+git branch -d foobar
+}}}
 
 
 
-------8<------8<------8<------8<------8<------8<------8<------8<--------

--
Page URL: <https://trac.macports.org/wiki/WorkingWithGit>
MacPorts <https://www.macports.org/>
Ports system for macOS

This is an automated message. Someone added your email address to be
notified of changes on 'WorkingWithGit' page.
If it was not you, please report to admin at macports.org.


More information about the macports-changes mailing list