Changes

From Genome Analysis Wiki
Jump to navigationJump to search
3,001 bytes added ,  18:50, 8 September 2015
→‎Bring in changes from a subtree's remote: It won't work if you only have the remote but not the branch.
Line 35: Line 35:  
#* <code>git commit -m ''Initialize the repository with all the files''</code>
 
#* <code>git commit -m ''Initialize the repository with all the files''</code>
    +
Note: The <code>shared</code> parameter on <code>git init</code> allows everyone in the same group to push to this repository.  If this is the case, add that parameter.
    
Continue to the next section if you want to create a bare repository for it to push to/pull from.
 
Continue to the next section if you want to create a bare repository for it to push to/pull from.
Line 43: Line 44:  
# Create the bare repository.
 
# Create the bare repository.
 
#* <code>git init --bare --shared ''bareRepoName''</code>
 
#* <code>git init --bare --shared ''bareRepoName''</code>
 +
#** The <code>shared</code> parameter allows everyone in the same group to push to this repository.  Remove that option if this is not the case.
 
# cd to your repository that you want link to this bare repository.
 
# cd to your repository that you want link to this bare repository.
 
# Set the remote.
 
# Set the remote.
Line 123: Line 125:     
== Check Branches ==
 
== Check Branches ==
*See what branches there are:
+
*See what branches there are locally:
 
** git branch
 
** git branch
 +
** Current branch marked with '*'
 +
 +
* To see all branches including remote branches:
 +
** git branch -a
 
** Current branch marked with '*'
 
** Current branch marked with '*'
   Line 170: Line 176:  
* git push origin ''branchName''
 
* git push origin ''branchName''
   −
== Work on a branch that exists on the remote ==
+
== Work on/Use a branch that exists on the remote ==
 
*To see all branches including remotes:
 
*To see all branches including remotes:
 
** git branch -a
 
** git branch -a
 
* Base work on a remote branch/merge back to it
 
* Base work on a remote branch/merge back to it
** git checkout --track origin/''branchName''
+
** git checkout -t origin/''branchName''
 
** Creates & checkouts branch called ''branchName''
 
** Creates & checkouts branch called ''branchName''
 
* Now push & pull from your ''branchName''
 
* Now push & pull from your ''branchName''
 +
 +
Note: A typical wrong way is: clone from the remote repository, then pull the branch
 +
 +
Note: A local branch name is only informative to you.  There is no relationship between that branch name and the branches named at the repository that you initially did the pull from.  So you may, for example, name your local branch "fix_karma_paired_end" or anything else arbitrary even if the remote branch is "0.8.8S".  As described above, the -t option will create a local branch named after the remote branch, also specify -b if you want to customize the name.
    
== Resolve a merge/pull conflict ==
 
== Resolve a merge/pull conflict ==
Line 188: Line 198:  
resolved the merge
 
resolved the merge
 
* You can also use a mergetool: git mergetool
 
* You can also use a mergetool: git mergetool
      
== Create a tag ==
 
== Create a tag ==
Line 208: Line 217:  
* Not automatically pushed to the remote
 
* Not automatically pushed to the remote
 
* git push origin ''tagName''
 
* git push origin ''tagName''
 +
 +
== Setup an email hook on pushes ==
 +
* cd ''yourDirectory''/.git/hooks
 +
* cp post-receive.sample post-receive
 +
* Uncomment the line at the end of post-receive that references post-receive-email
 +
* Add the following to ''yourDirectory''/.git/config:
 +
<pre>
 +
[hooks]
 +
mailinglist = "space delimited email addresses to email when changes are pushed"
 +
</pre>
 +
 +
== "Push rejected non-fast forward" ==
 +
Two possible answers:
 +
 +
(1). You did not pull the current branch before trying to push.
 +
 +
Solution: do a <code>git pull</code>, then retry the <code>git push</code>
 +
 +
(2). You only pulled a branch but want to push it back to master branch.
 +
 +
== Committed to the wrong branch ==
 +
If you have NOT yet pushed to a public repository and it was the last commit:
 +
*git reset --soft HEAD^
 +
** puts the changes back to staged.
 +
git checkout branch_you_want
 +
git commit
 +
 +
 +
== Subtrees ==
 +
=== Bring in changes from a subtree's remote ===
 +
If the remote is not already a part of this git repo:
 +
#Add other project as a branch and fetch (-f).
 +
#:<pre>git remote add -f libStatGen_remote https://github.com/statgen/libStatGen.git</pre>
 +
#Create & checkout a branch for the remote.
 +
#* taking <code>master</code>:
 +
#: <pre>git checkout -b libStatGen_branch libStatGen_remote/master</pre>
 +
#* taking a tag:
 +
#: <pre>git checkout -b vt_branch_SWS tags/SWS</pre>
 +
 +
If the branch is already a part of this git repo:
 +
#Checkout the branch
 +
#: <pre>git checkout libStatGen_branch</pre>
 +
#Bring in the new version
 +
#: <pre>git pull</pre>
 +
 +
=== Merge the changes from the subtree into the base repository ===
 +
#Go back to the master branch
 +
#: <pre>git checkout master</pre>
 +
#(Optional) Only if adding a new subdirectory, do:
 +
#: <pre>git read-tree --prefix=src/libStatGen -u libStatGen_branch</pre>
 +
#Merge in the new version.
 +
#: <pre>git merge --squash -s subtree --no-commit libStatGen_branch</pre>
 +
#:* --squash: do not merge histories
 +
#:* -s subtree: merge strategy
 +
#:*--no-commit: just merge, don’t commit the changes
 +
#Commit the changes
 +
#: <pre>git commit -m “message”</pre>
61

edits

Navigation menu