Git - What is it..?

rajsujayks

CSE Freak!
Can anyone here explain me in simple terms what Git is and how I can use it?

I have created a program in Java. I have the code. If I want to share the code, can I use git to do it?

I tried out SourceForge.net Even they use git. How do I add the code to git so that it shows up in SourceForge's page?
 

coolpcguy

Resistance is Futile.
Git is a version control program. It keeps a track of what changes were done across various commits.

For example: You can see the changes that I had done to my Auto-correct program over at revisions: *github.com/SathyaBhat/StackEd/commits/master/

Having version control is incredibly useful - if you screw up your program to a bad extend, you can always rollback to the last good commit. Have multiple branches, a stable branch where everything's always fine, a new-features branch where you can test out new features & so on.

You'll need to install git.

Git Book - Installing Git

Once you've installed it, you'll have to setup git

Help.GitHub - Set Up Git
Help.GitHub - Set Up Git

To start working with git, you'll have to initialize the repo first:

Code:
cd code/myjavaproject/
git init

Next add the files you want to track:
Code:
git add main.java

Once you've reached a point where you think you can come back to anytime, you'll want to create a commit

Code:
git commit -m "Message about what changes were done so far"

Now you'll want to push the changes to a remote server, SourceForge in this case (I'd recommend GitHub though)

Chose the below article, based on whatever you are using

Forge / documentation / Git - Beta
Git ? sourceforge

Once the remote has been setup (the part which does that is:

Code:
git remote add origin ssh://USERNAME@PROJECTNAME.git.sourceforge.net/gitroot/PROJECTNAME/REPONAME
git config branch.master.remote origin
)

you'll need to push the local changes to server:
Code:
git push origin master

There you go, your program's tracked by git, and pushed to SF.

Next time you do any change to the files which are being tracked, git will identify that.

You can see the status by typing
Code:
git status
on the directory where the git repo is.

To commit the changes, just add the files & do a git commit. (As shown).

The CLI seems daunting at first, but you'll get used to it. If you want a nice GUI I'd recommend Git Extensions for Windows or QGit for Linux.
 
OP
rajsujayks

rajsujayks

CSE Freak!
Thanks Mr. coolpcguy.... Awesome explanation..and I got an example in your repository too.. Thanks for that.. :) I'll come back if I need clarifications...
 
Top Bottom