Changes

From Genome Analysis Wiki
Jump to navigationJump to search
5,600 bytes added ,  16:52, 9 September 2011
no edit summary
Line 1: Line 1:  +
= Git FAQs =
 +
For more information on how to use git, see: [[How To Use Git]]
 +
 +
 +
== Learn how a specific command works ==
 +
{|border="1"
 +
! Command
 +
! Example
 +
|-
 +
| git help <command>
 +
| git help clone
 +
|-
 +
| man git-<command>
 +
| man git-clone
 +
|-
 +
| git-<command> -h
 +
| git-clone -h
 +
|}
 +
 +
 
== Turn an already existing directory into a Git Repository ==
 
== Turn an already existing directory into a Git Repository ==
   Line 33: Line 53:     
You can now operate as if you had cloned from bareRepoName.
 
You can now operate as if you had cloned from bareRepoName.
 +
 +
== Use a Previously Setup Repository ==
 +
Clone it:
 +
  git clone <repository to be cloned> [optional new directory name]
 +
 +
== Update files ==
 +
* Edit a file.
 +
* When done editing, [[#Commit/Store Changes|commit the changes]]
 +
 +
== Unmodify files ==
 +
Instructions are also given in <code>git status</code>
 +
* <code>git checkout -- ''fileName''</code>
 +
 +
== Identify non-committed changes ==
 +
* Using Command-Line (2 ways)
 +
** git status - list changed/removed/staged files
 +
** git diff - lists the differences
 +
* Using git-gui
 +
** They are listed under Unstaged Changes
 +
 +
== Stage files/changes prior to committing them ==
 +
* Using Command-Line (multiple ways)
 +
** git add <file1> <file2> (adds specified files)
 +
** git add .  (adds all files)
 +
*** first do a <code>git status</code> to see what files will be staged
 +
**** after, do a <code>git status</code> to verify you want those files staged
 +
* Using git-gui (multiple ways): Should see files move from Unstaged to Staged
 +
** Click on the file icons in the Unstaged Changes window
 +
** 2 Step process
 +
**#Select the files to be staged in the Unstaged Changes Window;
 +
**#Commit->Stage To Commit
 +
 +
== Unstage files ==
 +
Instructions are also given in <code>git status</code>
 +
* <code>git reset HEAD ''filename1 filename2''</code>
 +
 +
== Commit/Store Changes ==
 +
Files are already staged:
 +
* To see staged files use:
 +
** git diff --cached
 +
* Using Command-Line
 +
** git commit -m "your commit message"
 +
*** if you do not specify -m, it will open up your default editor for you to enter the message, enter it, save, and exit
 +
* Using git-gui
 +
** Press the "Commit" button
 +
 +
Files are not already staged (2 ways):
 +
* git commit -a -m "your commit message"
 +
** Always do a git status first - all modified files will be committed.
 +
* git add (adds to the index/stage); git commit -m "your commit message"
 +
 +
== Bringing in (Pulling) changes from source repository (the one you cloned from) ==
 +
*In your local/working repository:
 +
** git pull
 +
** Resolve any unresolved merges & commit those resolutions.
 +
 +
== Ignore files that you don't want to show up in <code>git status</code> ==
 +
Setup git to ignore files with certain names, extensions, etc
 +
 +
If all users of the repository will want to ignore the files:
 +
* Create/update a .gitignore file containing the files you want to ignore (use #'s as comments), for example:
 +
# Ignore editor created temp files
 +
*~
 +
# ignore object files.
 +
*.o
 +
 +
If the ignored files are specific for just you, add your ignores file (formatted like the .gitignore):
 +
*git config core.excludesfile ~/git/config/ignoreFiles
 +
 +
== Check Branches ==
 +
*See what branches there are:
 +
** git branch
 +
** Current branch marked with '*'
 +
 +
== Create New Branch ==
 +
First change to the branch (could be master, the default branch) you want your branch to start from.
 +
 +
* 2 ways to create a new branch and switch to it:
 +
** Create branch, then switch to it (default starting point is the same as the current branch):
 +
**# Create the branch
 +
**#* git branch <branch-name> [<start-point(branch/tag)>]
 +
**# Switch to a Specified Branch
 +
**#* git checkout <branch-name>
 +
** Create and switch to the branch in one step
 +
**# Create and switch to (checkout) a branch
 +
**#* git checkout -b <branch-name> <start-point>
 +
* See Your Branches - current one is marked with a "*"
 +
** git branch
 +
'''NOTES:'''
 +
* If you switch to the branch in one window, it switches it in all
 +
* Beware of switching branches when you have non-committed files.
 +
** Until you commit the files, they will be in all branches.
 +
** If a branch has a different head than your current branch for the non-committed files, the branch change fails.
 +
 +
== Merging Changes ==
 +
* Checkout the branch you want to merge into
 +
** git checkout branchMergeInto
 +
** Often: git checkout master
 +
* Merge the other branch into it
 +
** git merge branchMergingFrom
 +
* Resolve and commit any merge conflicts.
 +
* To Undo a merge before committing:
 +
** git reset --hard HEAD
 +
 +
Note: ”Fast forward” - no divergent work, just moves the pointer to
 +
the latest commit on the other branch
 +
 +
== Delete a Branch ==
 +
Delete branch after merging & you are done with it
 +
* git branch -d branchName
 +
* Make sure you have merged first!
 +
* Delete remote branch:
 +
* git push origin :branchName
 +
 +
== Share a Branch by pushing to the Remote ==
 +
* git push origin ''branchName''
 +
 +
== Work on a branch that exists on the remote ==
 +
*To see all branches including remotes:
 +
** git branch -a
 +
* Base work on a remote branch/merge back to it
 +
** git checkout --track origin/''branchName''
 +
** Creates & checkouts branch called ''branchName''
 +
* Now push & pull from your ''branchName''
 +
 +
== Resolve a merge/pull conflict ==
 +
* Make appropriate changes
 +
* Delete the <<<<<<<, =======, and >>>>>>>
 +
* Add to the staged files
 +
** git add nowMergedFile
 +
* Commit the merge
 +
** git commit
 +
** Update the default merge message with a description of how you
 +
resolved the merge
 +
* You can also use a mergetool: git mergetool
 +
 +
 +
== Create a tag ==
 +
Tags can be used when releasing, if you want to mark that version so you can
 +
go back to it
 +
 +
* git tag -a tagName -m 'tag description'
 +
* Example:
 +
git tag -a v1.1 -m 'version 1.1 contains the first version
 +
 +
== See what tags there are ==
 +
* git tag
 +
* git tag -l v1.1.*
 +
 +
== Get info on a tag==
 +
* git show ''tagName''
 +
 +
== Push Tag to remote ==
 +
* Not automatically pushed to the remote
 +
* git push origin ''tagName''

Navigation menu