Advice for new programmers: Use git
Why version control?
Stop losing your code
Without version control, There are so many ways to lose your code: deleting the wrong file, closing a window when you left the changes in the undo stack, uploading the wrong file version through FTP. Sometimes this isn't a big deal, but other times it can cost hours or days of work.
Sync your code across work stations.
If you have a remote repository it's trivial to sync your code across multiple.
Freedom to experiment
A seasoned engineer once told me that git can be used like a "crash helmet". This is the most unexpected benefit. If you think you're going to try something wacky, branch and it it works, use it, if it sucks, leave it.
sudo apt-get install git
OtherIf your os doesn't come with git, you can download binaries from the website
Getting startedTo start a local git repository
Create a readme and add it to the repo
or to add all the new files.
touch README.md git add README.md
Then to commit your changes
git add --all
To see that you in fact, did commit.
git commit -m "What you did"
Branching and mergingWhen experimenting, or making a new feature, its usually a good idea to create a new branch. Branching and merging with git is really easy.
To make a new branch
To see that you in fact, did switch branches
git checkout -b newbranch
So after you'd made some changes and want to merge back into master.
If their are no conflicts the commits will go straight in and you now have everything on master. When done with a branch its a good idea to remove them, otherwise things could get messy.
git checkout master git merge newbranch
git branch -d newbranch
Remote accountTo make your code available everywhere you have to have a remote repo. I use Github for my open source projects since the community is larger. If there is any reason you want to keep the code private (probably a good idea for in progress classes), Bitbucket offers unlimited private repos for small teams.
Once you have your new repo set up you can link it to your local repo.
Origin is the default remote repository, it can be called anything, but origin is the norm.
git remote add origin http://path/to/remote/repo
To push your code to the remote repository:
Every time a change is made locally, to add to the remote repo. Simply:
git push origin master
Now your code is stored on the internet!
git add --all git commit -m "What you did" git push
Working on multiple machinesOnce you have a remote repo you can get your code onto a new computer. On your second computer enter.
Now the code is on the new machine.
git clone http://path/to/remote/repo
After making some changes and pushing to a new repo, you'll want to get your changes back onto the original computer. To do thing you have a couple options.
Git pull performs a fetch (meaning get the changes), and then merge them into your current branch. Git rebase attempts to perform local and remote changes in order an avoid merging. Both will work. However pulling will add a bunch of merge commit messages into your log, which you might not want. You WILL want to you git pull if you think there might be a lot of conflicts.
git fetch && git rebase
SummaryGit is super awesome. It is critical in a group context, and very useful in an individual context. I would have had a much easier time in college and early pro career, if I knew about git.
Helpful applications:bash: grb (command line utility that makes working with remote branches easier)
osx: (source tree)