Skip to content

Starting with git and its command line

lol768 edited this page Jul 3, 2014 · 4 revisions

Git setup

Once you have successfully installed git for your platform and have access to a console where you can type git --version, you can start and configure it.

First thing first, you might want to let it know your name and your email. This way, every commit you make will be associated to you and your github account.

To setup your name, you'll need to run this command in your console:

git config --global user.name "Your Name Here"

Now, to setup your email (which should be the same as the one you used for your github account for it to link up), you'll need to run this command:

git config --global user.email "[email protected]"

Once these two steps are done, git is ready to use.

Cloning a repository

Once git is setup, you can clone your repository. To do so, just navigate to your online repo (which would be https://github.com/tenjava/your_name_here) and grab its url. Once you got it, you just need to run this line in your console and it will create a folder containing a clone of the github repository in your current directory:

git clone url_you_just_grabbed_goes_here

You can now enter it using cd your_repo_name and start hacking to your heart content.

Creating files and committing

Now that you have everything you need, you can start adding content to your repository.

Let's say you want to create a README (a README is a file placed at the root of your repo and describing your project. It will be displayed on the homepage of your online repo).

You can create your file using this command (or just use the text editor of your choice 😄):

echo What a fancy readme > README.md

If you now type git status, you'll see that the file you created is marked as untracked.

# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       README.md

You can simply add the file to the tracked files using

git add README.md

or add all the folders and its files recursively using

git add .

If you now type git status, you'll see that your file is now tracked.

# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file:   README.md
#

Once you got tracked files, you can just commit them using

git commit -m "Added a README"

Note that you can add a description by adding a new line:

git commit -m "Added a README
> 
> Which I'll need to make better soon"

Your first commit is done! Now that you know how to add files, you are good to go!

Sending your changes online

Now that you have worked a bit, you have some commits on your computer and you want to send them online because there are only a few minutes to go before the end of the contest. It is in fact, really simple, the only thing you have to type the first time is:

git push origin master

and you'll only need to type

git push

the other times.

When to commit

At the beginning, you'll surely add all your files, start developing your plugin for that awesome contest and totally forget about git, commits and stuff. It's ok, everybody starts the same way.

Although, you might want to make some commits at special moments:

  • When you have added a functionality,
  • When you have fixed a bug,
  • When you have a part of a part of a functionality done,
  • When you have so much work done, you think it's time to commit,
  • etc.

The thing you need to remember is that all that historic can come in handy when say, you add some functionality and it breaks another part of your work. You'll then need to read your previous commits and spot the one who broke the world. You'll then see the changes you made and (hopefully) find a fix. This job is pretty easy if you have committed your work often enough and you've used appropriate commit messages.

During the contest, you'll need to commit and push at least every 15 minutes so we can effectively verify the work is yours.

It can also sometime help you remember why you did a specific change or what it was related to.

Side note

If you need help with a specific problem or have questions of any kind, feel free to consult the very own github help and come join us on IRC.

If you have any questions (about the contest, git, Maven etc), please don't hesitate to send us a tweet @tenjava or ask in our IRC channel.

Clone this wiki locally