Difference between revisions of "Git"

From GLMWiki
Jump to: navigation, search
(Git Flow Process (example))
(Git Flow Process (example))
Line 75: Line 75:
  
 
==Git Flow Process (example)==
 
==Git Flow Process (example)==
This is merely an example. Things may not always follow this line of commands exactly.
+
:This is merely an example. Things may not always follow this line of commands exactly.
  
(0. '''ssh-add''')
+
:(0. '''ssh-add''')  
 +
::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 if you care for such convenience.
  
1. '''git clone git@cvs2:web/mywebsite.git www.mywebsite.com''' (like SVN checkout)
+
:1. '''git clone p1 p2.''' <br/>
 +
::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.
  
2. '''cd www.mywebsite.com'''
+
:2. '''cd www.mywebsite.com'''<br/>
 +
:: Go into the website's directory so that you can use git commands in the future.
  
3. '''git flow init''' (master, develop, feature, release, hotfix, support, V (only change from default) - this should only be necessary -once- the very first time anyone sets up the repository for the website)
+
:3. '''git flow init''' <br/>
 +
::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.
  
4. '''git branch -av'''  (shows what branch you are on, as well as the branches that exist both locally and remotely)
+
: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 develo'''p (unnecessary, but UNLIKE SVN this merely changes the branch you're currently on to ''Develop'')
+
: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''' (this creates the hotfix branch called 1.0.3)<br/>
+
:6. '''git flow hotfix start 1.0.3''' <br/>
(*. or: '''git flow feature start AwesomeFeature''')
+
::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 --
 
-- start up your favorite editor and make whatever changes to whichever project/files you please --
  
7. '''git status''' (will show you all changed files)
+
: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''' . (will make all files in all folders in the current directory ready for committing)<br/>
+
:8. '''git add .''' <br/>
(*. or to add a single file: ''git add .htaccess'')
+
::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''' (will commit changes to the main branch)<br/>
+
:9. '''git commit''' <br/>
(*. oops! Forgot a change/file? It's not too late to add: '''git commit --amend''' )
+
::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. liberal use of '''git status'''. This will also show the command '''git reset HEAD -- .gitignore.whatever''' to remove something you '''git add'''-ed (also works on folders)
+
: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'''' (this will bring you back to the develop branch and delete the hotfix branch after it merges its changes. Make note of your edits!)
+
: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 does the merge) <br/>  
+
::(*. '''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 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 a two-step process: '''git fetch''' takes it from the main repository onto your ''remotes'' branch, then '''git merge''' takes it from there to whatever branch you indicated (where you're likely working from) <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)
+
::(*. 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''' (to make sure you're on the branch you're meant to be)
+
:10. '''git branch -av'''  
 +
::Same command as before, to make sure what branch you're on.
  
11. '''git push origin develop''' (send changes to the remote main branch - TO origin FROM develop)<br/>
+
:11. '''git push origin develop'''  
(*. '''git push --all''' is an alternative though it may be safer to be precise. This must be followed by '''git push --tags''')
+
::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
+
: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'''~
+
:13. '''ssh ws6''' (or dev53 or whatever server), then '''cd /var/www/server/www.myweb'''~
  
14. '''git pull origin develop''' (this command may also be used on your own server kind of like ''svn checkout'', instead of cloning at step 1) <br/>
+
:14. '''git pull origin develop'''  
(*. on WS6 you use '''git pull origin ''master''''' instead, since it only has a master branch)
+
::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.
 +
 
 +
 
 +
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!)<br />
 +
'''git pull origin develop''' to make sure your files are up to date, when you're in the website's directory. Also used on the remote server to pull in the changes ''you'' have made/added/committed<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

Revision as of 11:38, 17 July 2014

Git

Git Docs

Git Pro Book

Git Tutorial

Git Flow Workflow

Install

Installing Git

Git for the first time

Setting up Git for the first time

Git Ignore File

create a file called .gitignore_global in you home directory

# OS generated files #
######################
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
._* 
*.swp 

# Gaslight Media Application specific #
# files that are updated on server    #
#######################################
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

SSH Keys

Creating your ssh keys (private/public)

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

How to sign your commit or tags

Reference

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

Git Flow Process (example)

This is merely an example. Things may not always follow this line of commands exactly.
(0. ssh-add)
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 if you care for such convenience.
1. git clone p1 p2.
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.
2. cd www.mywebsite.com
Go into the website's directory so that you can use git commands in the future.
3. git flow init
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.
4. git branch -av
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
Unlike SVN, this command merely changes the branch you're currently on to Develop
6. git flow hotfix start 1.0.3
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
This will show you all files that have been changed, and whether they are pending committing or adding.
8. git add .
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
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.
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'
(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)
(*. 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!)
(*. 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
(*. 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.


So, in summary, considering the repository has already been set up and you just want to make some changes:
git branch -av to see what branch you're on and which exist
git checkout develop to hop onto the branch called develop (this does not checkout like svn!)
git pull origin develop to make sure your files are up to date, when you're in the website's directory. Also used on the remote server to pull in the changes you have made/added/committed
git flow feature SomeName to start a feature branch named SomeName
git flow hotfix 1.7.2 to start a hotfix branch named 1.7.2
git status to see how your local file copies differ
git add someDir/someFile to add that file or folder to the list of things to be committed.
git reset HEAD someFile> to undo a git add, taking a file off the list of things to be committed.
git commit to commit changes to the branch. git commit --amend in case of last-minute additions
git push origin develop Send the committed changes from your Develop branch to the remote Origin branch.
gitk for a gui