Github Starting Guide for Total Newbies
Hello folks, this week i’ll write a straight and easy guide for young programmers who needs to learn Git and need to do it fast!
Your typical scenario is probably like this:
Welcome to your new workplace, hi! i am your senior, me and your coworkers use Git as revision service, i am sure you know all about it, right?
Don’t worry, it’s fine, take a deep breath and ask for a Coffee Break. Then sneak in the bathroom and read this guide. Quick, do it!
If you find any further problem with my guide, check out this one :
http://rogerdudler.github.com/git-guide/ which is way colorful and funny than mine.
1 – WTF is Git?
Repository tool. What is a repository? A stuff that save your ass when you override or destroy your boss’s code.
2 – Is this really useful?
Only if you work with other people at the same code.
3 – Do i need to read a book to learn it?
No. Give me just 10 minutes. It’s all about 10 console commands and nothing more.
4 – There are tons of GUI for Git, which one is the better?
Depends on the OS, for Win i’d suggest TortoiseSVN, but trust me, Git base GUI is enough.
5 – How i use it?
Here we are:
A. Download the stuffs
Even if Git is often used to manage some online repos, you need it installed locally. Here are the links, you’re gonna install Git Bash + Git GUI.
Git Bash is the command tool + basic stuff.
Git GUI is the UI, useful to see commits and other things.
Leave default options while installing. No deep shit.
B. Open the GIT Bash
Ok now you have a nice command tool opened. The first thing you need to know is that you can:
- Make a copy of something in an online repo
- Get a copy of something from an online repo
- Create a local repo
For each case navigate to the folder you want to use (empty or with files, we don’t care) and digit:
Ok, now Git will do stuff, initialize the folder, create some badass file to get things done.
When you will be inside a Git folder, from now on, you’ll see this:
(master) ! That means you’re a boss.
Ok now make a decision as a boss:
- I want to start anew
Start creating and doing stuff as none it's happened inside this folder
- I want to get a copy of a local folder and put it in the repo
git clone /path/to/repository
- I want to get a copy of a remote repository as my boss asked me to
git remote add origin /path/to/repository git pull origin master git pull --tags
For the last case you’ll need the repo access, no problem there. Github is nice for making test, but the free user tier is public, remeber that.
P.S.: You’ll need a couple of private/public key in most cases. Generate them using:
ssh-keygen -t dsa
C. Understand the Git-flow
When you work under a Git repo, as any other, you actually do you normal stuff, coding, adding files and so on. You modify your local copy, ok, easy to understand. After that, you want to send it to the repo, local or remote, first you “add” them to a virtual image of “what-is-changed” then you commit them, sending out the effective change to the repo. At last, you or your master will decide if the changes submitted are ok for the final version, and push it to the “origin”, the highest and most important source.
- Do stuff on your local files
Code Code Code
- Add stuff to the next Commit
git add *
Remember that there are many more add types, more accurate.
- Commit your changes locally
git commit -m "Commit message example"
- Push the commit to the remote/local parent branch
git push origin master
which is git push -destination- -source-
D. Become a Git-badass learning what branches are
A branch is where you work, making an example you were working on (Master) and you know that (Origin) is the stable revision, so you could make other sub-branches, this is useful when you don’t want that young programmers send the codes directly on the (Origin). You could assign them different branches with:
git checkout -b noob
git checkout -branchname- is the command for switching between branches, -b is for creating the branch, -d is for delete
So they’ll work on (Noob) from the time being, and after some times they could push their commits to (Master), so you could check them out, approve them and send them to the (Origin) in the next revision.
A useful command while using branches is
git pull master noob
which is the opposite of git push, you pull the different revision from the branch named master inside the branch named noob. Easy.
You could even use
git merge master
to merge (master) into the active branch (noob)
You could see a preview of the merged items by using
git diff master noob
E. Excellent commands for excellent programmers
- to know what files has been changed and probably need to be commited.
git tag 1.0.1 1b2e1d63ff git push --tags /* FOR REMOTE TAGS DELETE */ git tag -d 1.0.1 git push origin :refs/tags/1.0.1
- you could give versioning, useful in many case, and (extra) assign them commit codes
- gives the tag history back to you
git fetch origin git reset --hard origin/master
- drops all the current changes and goes back to the origin version
git config color.ui true git config format.pretty oneline
- cool formatting style
F. Using the Git GUI
Open the UI and open the folder used by GIT to make stuff.
Don’t compress the archive if the GUI ask it and open the dropdown “Archive” and “Show changes of all branches” to have a visual feedback of what’s happened in the repos.
Nicely done, you could now use Git effectly.