and changes to those files • Save the state of files in a historical timeline (repository) • What, When, Why, W ho Subversion, Git, Perforce, IBM Clearcase, Mercurial, ... Jan Henckens (@jannemans) - PHP Leuven - March 2015 11
control system designed to handle everything from small to very large projects with speed and efficiency.” Distributed? Works offline, several users have their own separate file history (these can later on be merged) Jan Henckens (@jannemans) - PHP Leuven - March 2015 12
init: git init Git automatically creates a (hidden) .git folder containing: • Meta information • The entire history Jan Henckens (@jannemans) - PHP Leuven - March 2015 13
Select which files you want to save using git add → staging 2) Actually save them using git commit → committing Jan Henckens (@jannemans) - PHP Leuven - March 2015 15
• Write clean commit messages • Small changes per commit • One bug fix per commit git commit -m “message” Jan Henckens (@jannemans) - PHP Leuven - March 2015 18
git reset HEAD --hard The entire working directory will go back to the last committed state, cannot be undone Unstage all + stash all changes => git stash The entire working directory will go back to the last committed state, can be undone as the state is saved in a stash. Jan Henckens (@jannemans) - PHP Leuven - March 2015 20
git log --oneline makes it a bit better • git log --graph --pretty=format:'%Cred%h%Creset - %C(bold yellow)%d%Creset %s %Cgreen(%cr) %C(cursive blue)<%an>%Creset' --abbrev-commit (via @bramus) (might want to alias that) Jan Henckens (@jannemans) - PHP Leuven - March 2015 28
checked out (= active) revision (= commit) To move the HEAD you checkout a revision: git checkout revision Jan Henckens (@jannemans) - PHP Leuven - March 2015 32
'experiment' • git checkout experiment => moves HEAD to the new branch • Changes are committed on the active branch Jan Henckens (@jannemans) - PHP Leuven - March 2015 34
which you want to merge: git checkout master • git merge expermiment will merge the changes from experiment with master • A merge commit is created Jan Henckens (@jannemans) - PHP Leuven - March 2015 35
branch • If the branch hasn't been merged Git will yell at you about it (use -D instead of -d to overwrite that) Jan Henckens (@jannemans) - PHP Leuven - March 2015 36
both branches => Merge conflict • Fix the conflict in a text editor, stage the file and commit • Pick the version from the branch you're on (HEAD): git checkout --ours conflictedfile • Pick the version from the branch your trying to merge into HEAD: git checkout --theirs conflictedfile Jan Henckens (@jannemans) - PHP Leuven - March 2015 37
server, in git this server is called a remote • A remote has a name (defaulting to origin) and a url • Multiple people can access the same remote • Multiple remotes are possible (distributed) • push / pull to keep the local and remote copy in sync Jan Henckens (@jannemans) - PHP Leuven - March 2015 38
doesn't exist yet: git clone [email protected]:laravel/framework.git • a local copy of the master branch will be created • includes the entire commit history Jan Henckens (@jannemans) - PHP Leuven - March 2015 39
hotfixes • master/develop • features (starts from develop) • releases (merges develop into master) • hotfix (starts from master) Jan Henckens (@jannemans) - PHP Leuven - March 2015 43
want to track • Be careful when committing config files (credentials, api keys, etc) • ‘git blame’ - see who broke things and when Jan Henckens (@jannemans) - PHP Leuven - March 2015 44
own projects • You don’t have to know all this by heart • You don’t have to use the command line • Stick with it, it’s not that hard Jan Henckens (@jannemans) - PHP Leuven - March 2015 47
• Connect the service to your server (ssh, sftp) • Deploy all the things But but but • Database changes? Jan Henckens (@jannemans) - PHP Leuven - March 2015 51