Welcome to TRiBot Forums

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Encoded

Git Tutorial

9 posts in this topic

hIUWbqc.png

What is Git?
"Git is a version control system (VCS) for software development. It is a distributed revision control system with an emphasis on speed, data integrity, and support for distributed, non-linear workflows." - Wikipedia
In simpler terms, git allows you to revert changes in your project if needed and allows you to easily collaborate with others. 
How do I get Git?
You can follow the download instructions for your OS here: http://git-scm.com/downloads
 
After installing git, you will want to set your name and email.

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Creating a Repository
We are assuming you have already set up a project via an IDE.
cd to the main directory of your project and git init to create the repository.

cd IdeaProjects/TRiBot/src
git init

Adding and Committing files to the Repository
Think of commits as different versions of your project. You can switch between commits as needed. You can add entire directories as well as individual files.

git add scripts/ExampleScript.java
git commit -m 'Descriptive commit message'

Status
We can use the git status command to display the state of the working directory and the staging area. It lets you see which changes have been staged, which haven’t, and which files aren’t being tracked by Git. Status output does not show you any information regarding the committed project history. For history you use git log.

git status

Viewing Commit History
We use the git log command to view commit history. There are many parameters that can be added to the log command to further refine the returned commit history.

git log

Reverting to a Previous Commit
To revert to a previous commit we use the git checkout command.

git checkout <commit>

If we only want to revert a specific file, we can do so.

git checkout <commit> <file>

You now should know enough about git to be able to easily revert any undesirable changes to your scripts and increase development speed and efficiency.
 


Uploading and Pushing to a Remote Repository

We will assume you already have a git repository setup. Now you just need to add the url to remote repository and push to it.

cd /path/to/my/repo
git remote add origin https:[email protected]/Encoded/example.git
git push -u origin --all # pushes up the repo and its refs for the first time
git push origin --tags # pushes up any tags

Now when you make commits, you can push them to the remote repository.

git push origin master

Origin is the remote name and master is the branch name.


Using branches, collaborating with others, and IDE integration coming at a later time.

Edited by Encoded
3 people like this

Share this post


Link to post
Share on other sites

If you use windows you can also use GitHub's windows GUI for something more visual.

Using the command line isn't scary :P
2 people like this

Share this post


Link to post
Share on other sites

I was trying to use the "fancy git hub interface" and got a little confused, using the command line was much easier to understand. Thanks Encoded :) 

Share this post


Link to post
Share on other sites

Added how to push to a remote repository such as GitHub.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.