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. 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]
  
 
:(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.
+
::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.
  
 
:1. '''git clone p1 p2.''' <br/>
 
:1. '''git clone p1 p2.''' <br/>

Revision as of 14:48, 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. See also: Cheat Sheet 1, Cheat Sheet 2, or Cheat Sheet 3
(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 Setting up ssh to not need a password 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