Difference between revisions of "Git help"

Jump to navigation Jump to search
Line 109: Line 109:
#  README.md                |    5 +++--
#  README.md                |    5 +++--
#  1 file changed, 3 insertions(+), 2 deletions(-)
#  1 file changed, 3 insertions(+), 2 deletions(-)
=== Releases: Tags ===
git checkout <branch>
git tag -a v0.0.17 -m "plexWatch v0.0.17 Release"

Revision as of 14:01, 10 August 2013

Merging Branches


Merging Dev -> Master

  • Will checkout the 'master' branch and merge from the 'dev' branch. Any applicable changes within 'dev' will be in 'master' once this command has completed.
git checkout master
git merge dev

Merging Master -> Dev

  • Will checkout the 'master' branch and merge from the 'dev' branch. Any applicable changes within 'dev' will be in 'master' once this command has completed.
git checkout dev
git merge master

Syncing a Forked Repo

The Setup

Before you can sync, you need to add a remote that points to the upstream repository. You may have done this when you originally forked.

Tip: Syncing your fork only updates your local copy of the repository; it does not update your repository on GitHub.

git remote -v
# List the current remotes
# origin  https://github.com/user/repo.git (fetch)
# origin  https://github.com/user/repo.git (push)
git remote add upstream https://github.com/otheruser/repo.git
# Set a new remote
git remote -v
# Verify new remote
# origin    https://github.com/user/repo.git (fetch)
# origin    https://github.com/user/repo.git (push)
# upstream  https://github.com/otheruser/repo.git (fetch)
# upstream  https://github.com/otheruser/repo.git (push)


There are two steps required to sync your repository with the upstream: first you must fetch from the remote, then you must merge the desired branch into your local branch.


Fetching from the remote repository will bring in its branches and their respective commits. These are stored in your local repository unders special branches.

git fetch upstream
# Grab the upstream remote's branches
# remote: Counting objects: 75, done.
# remote: Compressing objects: 100% (53/53), done.
# remote: Total 62 (delta 27), reused 44 (delta 9)
# Unpacking objects: 100% (62/62), done.
# From https://github.com/otheruser/repo
#  * [new branch]      master     -> upstream/master

We now have the upstream's master branch stored in a local branch, upstream/master

git branch -va
# List all local and remote-tracking branches
# * master                  a422352 My local commit
#   remotes/origin/HEAD     -> origin/master
#   remotes/origin/master   a422352 My local commit
#   remotes/upstream/master 5fdff0f Some upstream commit


Now that we have fetched the upstream repository, we want to merge its changes into our local branch. This will bring that branch into sync with the upstream, without losing our local changes.

git checkout master
# Check out our local master branch
# Switched to branch 'master'
git merge upstream/master
# Merge upstream's master into our own
# Updating a422352..5fdff0f
# Fast-forward
#  README                    |    9 -------
#  README.md                 |    7 ++++++
#  2 files changed, 7 insertions(+), 9 deletions(-)
#  delete mode 100644 README
#  create mode 100644 README.md

If your local branch didn't have any unique commits, git will instead perform a "fast-forward":

git merge upstream/master
# Updating 34e91da..16c56ad
# Fast-forward
#  README.md                 |    5 +++--
#  1 file changed, 3 insertions(+), 2 deletions(-)


git checkout branch
git rebase master
#First, rewinding head to replay your work on top of it...
#Applying: added staged command
git pull
git push
== Tags ==
=== Delete ===
git tag
git tag -d test-tag
 Deleted tag 'test-tag' (was 865ff0f)
git push origin :refs/tags/test-tag
 To git@github.com:ljunkie/roku-client-public.git
 - [deleted]         test-tag