Difference between revisions of "Git"

From GLMWiki
Jump to: navigation, search
 
(42 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Image:Git-Logo-2Color.png|center|thumb|Git]]
+
[[Image:Git-Icon.png|center|Git]]
 +
==GLM Git Guide==
 +
[[The Great GLM Git Guide]]
 +
 
 
==Git Docs==
 
==Git Docs==
 
[http://try.github.com/ Try git tutorial]
 
[http://try.github.com/ Try git tutorial]
Line 11: Line 14:
 
[http://www.atlassian.com/git/tutorial/remote-repositories#!pull git pull --rebase]
 
[http://www.atlassian.com/git/tutorial/remote-repositories#!pull git pull --rebase]
  
==Install==
+
==Installation & Initial Setup==
[[Installing Git]]
+
[[Git Installation & Initial Setup]]
  
==Git for the first time==
+
==Setup ssh-agent==
[[Setting up Git for the first time]]
+
[[ssh-agent on windows(git bash)]]
 
+
== Git Ignore File ==
+
create a file called .gitignore_global in you home directory
+
git config --global core.excludesfile ~/.gitignore_global
+
<pre>
+
# OS generated files #
+
######################
+
.DS_Store*
+
ehthumbs.db
+
Icon?
+
Thumbs.db
+
._*
+
*.swp
+
 
+
# Gaslight Media Application specific #
+
# files that are updated on server    #
+
#######################################
+
admin/logs/
+
GLM_site_check.phtml
+
iconCache/
+
uploads/
+
cache/
+
compiled/
+
compile/
+
original/
+
resized/
+
midsized/
+
thumb/
+
thumbs/
+
ht_images/
+
photo-large/
+
photo-small/
+
prototype/
+
weather-feed.xml
+
php.error
+
reports/
+
editimagesworkwith/
+
editimagesoriginal/
+
editedImages/
+
editimagespng/
+
.buildpath
+
.settings
+
.project
+
.svn
+
nbproject/
+
smarty/
+
</pre>
+
 
+
==SSH Keys==
+
[[Creating your ssh keys (private/public)]]
+
  
 
==Git-Svn==
 
==Git-Svn==
Line 73: Line 26:
  
 
==Gitolite==
 
==Gitolite==
[[Creating a new Git repo]]
+
[[The Great GLM Git Guide#Creating a new Git repo|Creating a new Git repo]]
  
 
==gpg signing==
 
==gpg signing==
[[How to sign your commit or tags]]
+
If you’re making signed annotated tags (as discussed in Chapter 2 of Git Pro), setting your GPG signing key as a configuration setting makes things easier. Set your key ID like so:
  
==Reference==
+
  git config --global user.signingkey <gpg-key-id>
git book online
+
http://git-scm.com/book
+
 
+
==Tracking Branches==
+
To set your current branch as a tracking branch
+
  git branch --set-upstream develop origin/develop
+
git branch --set-upstream master origin/master
+
  
 
==Git New Website Setup Checklist==
 
==Git New Website Setup Checklist==
phing install
+
[[The Great GLM Git Guide#Git New Website Setup Checklist|Git New Website Setup Checklist]]
phing specificApp
+
git init
+
git flow init: all defaults except the version tag prefix, which is v
+
git status
+
git add .
+
git commit -m "Initial Commit"
+
OR git commit, so you can check files, then "Initial Commit"
+
git push --all
+
git push --tags
+
git branch --set-upstream develop origin/develop
+
git branch --set-upstream master origin/master
+
  
==Git Flow Process (example)==
+
== Git Flow ==
:This is merely an example. Things may not always follow this line of commands exactly. See also: [http://www.ashep.org/wp-content/uploads/2012/02/git-cheat-sheet-large.png Cheat Sheet 1], [https://source.android.com/images/git-repo-1.png Cheat Sheet 2], or [http://image.slidesharecdn.com/gitcheatsheet-131205141010-phpapp02/95/git-cheat-sheet-1-638.jpg?cb=1386274237 Cheat Sheet 3]
+
[[The Great GLM Git Guide#Git Flow|Git Flow]]
  
:(0. '''ssh-add''')
+
== Git home config file ==
::This is optional, to avoid having to enter your password every time you SSH into a remote server. Have a look at [https://www.debian.org/devel/passwordlessssh Setting up ssh to not need a password] if you care for such convenience.
+
[[The_Great_GLM_Git_Guide#Git_home_config_file| Git home config file]]
  
:1. '''git clone p1 p2.''' <br/>
+
== Git Ignore File ==
::This is similar to svn checkout. You take the repository from the first parameter, and put it into the second. e.g.: '''git clone git@cvs2:web/mywebsite.git www.mywebsite.com'''. If you just want to update, and aren't making your first changes to a project, do '''git pull origin develop''' instead.[first do git flow init]
+
[[The_Great_GLM_Git_Guide#Git_ignore_file|Git Ignore File Setup]]
  
:2. '''cd www.mywebsite.com'''<br/>
+
==SSH Keys==
:: Go into the website's directory so that you can use git commands in the future.
+
[[Creating your ssh keys (private/public)]]
  
:3. '''git flow init''' <br/>
+
==Reference==
::You will be asked things. Just hit enter for master, develop, feature, release, hotfix and support, and on the final one type the letter V - this should only be necessary -once- the very first time anyone sets up the repository for the website.
+
git book online
 
+
http://git-scm.com/book
:4. '''git branch -av'''  <br/>
+
::This shows what branch you are on, as well as the branches that exist both locally and remotely. I think -av means show me All branches, and be Verbose.
+
 
+
:5. '''git checkout develop''' <br/>
+
::Unlike SVN, this command merely changes the branch you're currently on to ''Develop''
+
 
+
:6. '''git flow hotfix start 1.0.3''' <br/>
+
::This creates the hotfix branch called 1.0.3. Another example is '''git flow feature start AwesomeFeature'''. You will automatically be put into that branch, so that you will work from it.
+
 
+
-- start up your favorite editor and make whatever changes to whichever project/files you please --
+
 
+
:7. '''git status''' <br/>
+
::This will show you all files that have been changed, and whether they are pending committing or adding.
+
 
+
:8. '''git add .''' <br/>
+
::Be mindful of the period. This will make all files in all folders under the current directory ready for committing. To add a single file, for example: '''git add .htaccess'''.
+
 
+
:9. '''git commit''' <br/>
+
::This will commit changes to the main branch. If you did this and forgot to change/add a certain file, simply do '''git commit --amend''' when you're ready.
+
 
+
:10. make liberal use of '''git status'''. <br/>
+
::This will also show the command '''git reset HEAD <file> ''' to remove something you '''git add'''-ed in error (the command also works on folders). e.g. '''git reset HEAD .htaccess'''
+
 
+
:11. '''git flow hotfix finish '1.0.3'''' <br />
+
::(this will bring you back to the develop branch and delete the hotfix branch after it merges its changes. Make note of your edits!)
+
 
+
::(*. '''git flow feature publish someFeature''' is another example, though '''publish''' doesn't remove the branch, it merely merges your changes with the main branch) <br/>
+
::(*. Git may at some point complain about the fact that there are changes to wherever you're trying to commit/push to. It's merely a matter of doing '''git pull origin develop''' (where origin is the name of the branch you're taking it from, and develop is the branch you're taking it to) so that you're up-to-date!)<br/>
+
::(*. '''git pull''' is really two commands combined into one: '''git fetch''' takes it from the main repository onto your ''remotes'' branch, then '''git merge''' takes it from ''remotes'' to whatever branch you indicated such as Develop or feature/someFeature <br/>
+
::(*. This is also when you may realize you didn't yet start a branch, and you've already made changes. Have a look at '''git stash''', which will essentially put all changes into a separate stash. Then '''git flow feature start awesomeFeature''', which should put you on that branch, then do '''git stash pop''' to drop the stash onto that branch, after which the branch can be finished or published as noted above)
+
 
+
:10. '''git branch -av'''
+
::Same command as before, to make sure what branch you're on.
+
 
+
:11. '''git push origin develop'''
+
::This will send the committed changes to the remote main branch - this will push it TO origin FROM develop.
+
 
+
:12. '''gitk''' to marvel at a graphical representation of the good you've done today
+
 
+
:13. '''ssh ws6''' (or dev53 or whatever server), then '''cd /var/www/server/www.myweb'''~
+
 
+
:14. '''git pull origin develop'''
+
::This has to be done for the changes you made, added, committed and pushed to actually have effect. This command may also be used on your own server, sort of like ''svn checkout'', instead of cloning at step 1. On WS6 you use '''git pull origin ''master''''' instead, since it only has a master branch.
+
 
+
:15. '''git pull --all'''
+
::This will fetch all branches from origin and merge them with their tracking branches.
+
 
+
:16 '''git branch -u origin/develop develop''' && '''git branch -u origin/master master'''
+
::setup your (local) branches as tracking branches (if you did git init)
+
 
+
 
+
So, in summary, considering the repository has already been set up and you just want to make some changes: <br />
+
'''git branch -av''' to see what branch you're on and which exist<br />
+
'''git checkout develop''' to hop onto the branch called develop (this does not checkout like svn! git pull does that)<br />
+
'''git pull origin develop''' to make sure your files are up to date, when you're in the website's directory. Most similar to svn checkout.<br />
+
'''git flow feature SomeName''' to start a feature branch named SomeName<br />
+
'''git flow hotfix 1.7.2''' to start a hotfix branch named 1.7.2<br />
+
'''git status''' to see how your local file copies differ<br />
+
'''git add someDir/someFile''' to add that file or folder to the list of things to be committed.<br />
+
'''git reset HEAD someFile>''' to undo a git add, taking a file off the list of things to be committed.<br />
+
'''git commit''' to commit changes to the branch. '''git commit --amend''' in case of last-minute additions<br />
+
'''git push origin develop''' Send the committed changes ''from'' your Develop branch ''to'' the remote Origin branch.<br />
+
'''gitk''' for a gui
+

Latest revision as of 10:26, 9 June 2016

Git

GLM Git Guide

The Great GLM Git Guide

Git Docs

Try git tutorial

Git Pro Book

Git Tutorial

Git Flow Workflow

git pull --rebase

Installation & Initial Setup

Git Installation & Initial Setup

Setup ssh-agent

ssh-agent on windows(git bash)

Git-Svn

Checking out a site from svn with git (limit git) git svn http://git-scm.com/book/ch8-1.html

Gitolite

Creating a new Git repo

gpg signing

If you’re making signed annotated tags (as discussed in Chapter 2 of Git Pro), setting your GPG signing key as a configuration setting makes things easier. Set your key ID like so:

git config --global user.signingkey <gpg-key-id>

Git New Website Setup Checklist

Git New Website Setup Checklist

Git Flow

Git Flow

Git home config file

Git home config file

Git Ignore File

Git Ignore File Setup

SSH Keys

Creating your ssh keys (private/public)

Reference

git book online http://git-scm.com/book