So I’m back working with Dinis for a little bit..and true to form I ended up needing to learn some stuff to proceed. Which is fine, I don’t complain 🙂 .. so this time I needed to learn a little bit more about Git. Now I know it’s not strictly Team Mentor stuff…but I figured that anyone playing with TeamMentor in the future MUST know about Git..so I’m going to write a few posts on my experience (generically) with Git and probably Git with respect to TM if it doesn’t overlap with these posts ( 1 and 2) from Dinis.
So I did this nice little course from CodeSchool which gave me an introduction to Git and I’d like to very quickly talk about it without regurgitating stuff found everywhere. In a way..this post too is easily found, but I want to talk a bit just for the sake of continuity in this blog for me. Here goes:
You initialize a Git repository on your local machine first using git init. You then write code and save it in some files locally. Now you want to upload these files so that they can be viewed and worked upon by everyone. You use the command git add <filename/filename with wildcard> to do this. Note that git add doesn’t add files to the server; it just tracks files you “want” to eventually add on your machine. Once you’re through adding stuff in..you have to run git commit -m “comment” to confirm that you want to add these files in. Note that all this is still local.
Now you want to push all your local stuff to github. You use git remote add to create a new repository on the git server somewhere. That creates an empty repo. Then you use git push to push all your local files to the server. You can use git reset <filename> to remove files locally from your staging area; prior to pushing stuff over. You can go back to how things were using git checkout. Do note I’m not giving you exact commands; I’m fully aware of that..this is just a “flow overview” for me to refer back to sometime if I need it (and maybe for others).
Now all your code is in there. Say you now shared this repo and tons of people made tons of changes and you want to see what you can either use git pull or git clone. You can see what has changed using git diff HEAD.
Say you now want to make some changes to your code but aren’t sure if your changes will work, use git branches. Create a new branch, put all your changes into a branch and then add it back to the main branch if you want to. This can be done using git branch and git checkout to switch to that branch. If you want to remove a few files that you ‘dont’ want in your final code, you can use git rm to remove these files from the disk. Note that all this is happening inside the branch.
Add, Remove whatever you want within this branch. Use git checkout to come back to the “source branch” and then use git merge to join the destination branch to the source branch. You can eventually whop this branch off using git delete, coz you don’t need it after you’ve merged it.
Ha. So there it is. A sort of whirlwind intro to the heart of Git. Its probably a fraction of what’s actually possible but it’s a start. I like writing; I think it makes me better at whatever I’m writing about.