Git help: Difference between revisions

From RARForge
Jump to navigation Jump to search
(Created page with "== 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 ...")
 
 
(24 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Merging Dev -> Master ==
== autocompletion ==
 
http://stackoverflow.com/questions/9550447/is-there-a-shortcut-for-git-branch-name
 
<source>
# centos/rhel
wget https://raw.github.com/git/git/master/contrib/completion/git-completion.bash -O ~/.git-completion
emacs ~/.bash_profile
source ~/.git-completion
</source>
 
 
 
 
== cherry-pick ==
 
* http://wiki.koha-community.org/wiki/Using_Git_Cherry_Pick
 
Example:
* Source Branch: dev  ( what we want to cherry pick from )
* Target Branch: test
<source>
# checkout your target branch ( the branch you want to merge into )
git checkout test
 
# create a new branch -- easier to redo mistakes ( delete branch and start over )
git branch test-cp
 
# find commits you want to cherry-pick ( in this case we are cherry picking from "dev")
git log --pretty=oneline dev
 
# pick commits from bottom to top ( repeat for all commits)
git cherry-pick "hash"
 
# check results
git diff test..test-cp
 
# if you are happy with results
git checkout test
git merge test-cp
git push
</source>
 
 
 
 
== Branches ==
 
=== create ===
<source>
git checkout branch
git branch newbranchname
git checkout newbranchname
</source>
 
=== pushing ===
<source>
git checkout newbranchname
git push origin newbanchname
</source>
 
=== deleting ===
<source>
git branch -D newbranchname
git push origin :newbranchname
</source>
 
=== Merging ===
 
http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging
 
==== 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.
* 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.


Line 7: Line 78:
</source>
</source>


== Mering Master -> 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.
* 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.


Line 13: Line 86:
git checkout dev
git checkout dev
git merge master
git merge master
</source>
==== Selective Merge - Patches ====
* merging 'mybranch' with updates from 'master'
<source>
git checkout mybranch
git branch merge_master_mybranch_patch
git checkout master
git diff --no-prefix mybranch > mybranch.patch
</source>
* Edit the mybranch.patch to your needs.. excluding changes you do not want from master
* When you are ready to patch - checkout your branch 'mybranch' to patch
<source>
git checkout merge_master_mybranch_patch
patch -p0 < mybranch.patch
git commit -am 'merge master with mybranch.patch'
git push
</source>
* Now if you are happy with the changes.. lets actually merge the changes with your branch
<source>
git checkout mybranch
git merge merge_master_mybranch_patch
git push
</source>
== Syncing a Forked Repo ==
* https://help.github.com/articles/syncing-a-fork
* http://robots.thoughtbot.com/post/5133345960/keeping-a-github-fork-updated
===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.
<source>
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)
</source>
===Syncing===
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.
https://github.com/emesene/emesene/wiki/GitHowTo
=== Just reset from Head ===
<source>
git fetch upstream
git checkout master
git reset --hard upstream/master 
git push origin master --force
</source>
====Fetching====
Fetching from the remote repository will bring in its branches and their respective commits. These are stored in your local repository unders special branches.
<source>
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
</source>
We now have the upstream's master branch stored in a local branch, upstream/master
<source>
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
</source>
====Merging====
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.
<source>
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
</source>
If your local branch didn't have any unique commits, git will instead perform a "fast-forward":
<source>
git merge upstream/master
# Updating 34e91da..16c56ad
# Fast-forward
#  README.md                |    5 +++--
#  1 file changed, 3 insertions(+), 2 deletions(-)
</source>
=== checkout upstream ===
<source>
git checkout -b upstream upstream/master
</source>
== Rebase ==
* http://git-scm.com/book/ch3-6.html
<source>
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
</source>
== Tags (releases) ==
=== Create ===
<source>
git checkout <branch>
git tag -a v0.0.17 -m "plexWatch v0.0.17 Release"
git push --tags
</source>
=== Delete ===
<source>
git tag
v2.6.6-20130810-rf
v2.6.6-rf
test-tag
</source>
<source>
git tag -d test-tag
Deleted tag 'test-tag' (was 865ff0f)
</source>
<source>
git push origin :refs/tags/test-tag
To git@github.com:ljunkie/roku-client-public.git
- [deleted]        test-tag
</source>
</source>


[[Category:How-to]]
[[Category:How-to]]
[[Category:Linux]]
[[Category:Linux]]

Latest revision as of 00:42, 8 November 2013

autocompletion[edit]

http://stackoverflow.com/questions/9550447/is-there-a-shortcut-for-git-branch-name

<source>

  1. centos/rhel

wget https://raw.github.com/git/git/master/contrib/completion/git-completion.bash -O ~/.git-completion emacs ~/.bash_profile source ~/.git-completion </source>



cherry-pick[edit]

Example:

  • Source Branch: dev ( what we want to cherry pick from )
  • Target Branch: test

<source>

  1. checkout your target branch ( the branch you want to merge into )

git checkout test

  1. create a new branch -- easier to redo mistakes ( delete branch and start over )

git branch test-cp

  1. find commits you want to cherry-pick ( in this case we are cherry picking from "dev")

git log --pretty=oneline dev

  1. pick commits from bottom to top ( repeat for all commits)

git cherry-pick "hash"

  1. check results

git diff test..test-cp

  1. if you are happy with results

git checkout test git merge test-cp git push </source>



Branches[edit]

create[edit]

<source> git checkout branch git branch newbranchname git checkout newbranchname </source>

pushing[edit]

<source> git checkout newbranchname git push origin newbanchname </source>

deleting[edit]

<source> git branch -D newbranchname git push origin :newbranchname </source>

Merging[edit]

http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging

Merging Dev -> Master[edit]

  • 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.

<source> git checkout master git merge dev </source>


Merging Master -> Dev[edit]

  • 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.

<source> git checkout dev git merge master </source>



Selective Merge - Patches[edit]

  • merging 'mybranch' with updates from 'master'

<source> git checkout mybranch git branch merge_master_mybranch_patch git checkout master git diff --no-prefix mybranch > mybranch.patch </source>

  • Edit the mybranch.patch to your needs.. excluding changes you do not want from master
  • When you are ready to patch - checkout your branch 'mybranch' to patch

<source> git checkout merge_master_mybranch_patch patch -p0 < mybranch.patch git commit -am 'merge master with mybranch.patch' git push </source>

  • Now if you are happy with the changes.. lets actually merge the changes with your branch

<source> git checkout mybranch git merge merge_master_mybranch_patch git push </source>



Syncing a Forked Repo[edit]

The Setup[edit]

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. <source> git remote -v

  1. List the current remotes
  2. origin https://github.com/user/repo.git (fetch)
  3. origin https://github.com/user/repo.git (push)

git remote add upstream https://github.com/otheruser/repo.git

  1. Set a new remote

git remote -v

  1. Verify new remote
  2. origin https://github.com/user/repo.git (fetch)
  3. origin https://github.com/user/repo.git (push)
  4. upstream https://github.com/otheruser/repo.git (fetch)
  5. upstream https://github.com/otheruser/repo.git (push)

</source>


Syncing[edit]

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.

https://github.com/emesene/emesene/wiki/GitHowTo

Just reset from Head[edit]

<source> git fetch upstream git checkout master git reset --hard upstream/master git push origin master --force </source>


Fetching[edit]

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

<source> git fetch upstream

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

</source>

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

<source> git branch -va

  1. List all local and remote-tracking branches
  2. * master a422352 My local commit
  3. remotes/origin/HEAD -> origin/master
  4. remotes/origin/master a422352 My local commit
  5. remotes/upstream/master 5fdff0f Some upstream commit

</source>


Merging[edit]

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.


<source> git checkout master

  1. Check out our local master branch
  2. Switched to branch 'master'

git merge upstream/master

  1. Merge upstream's master into our own
  2. Updating a422352..5fdff0f
  3. Fast-forward
  4. README | 9 -------
  5. README.md | 7 ++++++
  6. 2 files changed, 7 insertions(+), 9 deletions(-)
  7. delete mode 100644 README
  8. create mode 100644 README.md

</source>

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

<source> git merge upstream/master

  1. Updating 34e91da..16c56ad
  2. Fast-forward
  3. README.md | 5 +++--
  4. 1 file changed, 3 insertions(+), 2 deletions(-)

</source>

checkout upstream[edit]

<source> git checkout -b upstream upstream/master </source>



Rebase[edit]

<source> git checkout branch git rebase master

  1. First, rewinding head to replay your work on top of it...
  2. Applying: added staged command

git pull git push </source>



Tags (releases)[edit]

Create[edit]

<source> git checkout <branch> git tag -a v0.0.17 -m "plexWatch v0.0.17 Release" git push --tags </source>

Delete[edit]

<source> git tag

v2.6.6-20130810-rf
v2.6.6-rf
test-tag

</source> <source> git tag -d test-tag

Deleted tag 'test-tag' (was 865ff0f)

</source> <source> git push origin :refs/tags/test-tag

To git@github.com:ljunkie/roku-client-public.git
- [deleted]         test-tag

</source>