Jump to content
Encoded

Git Tutorial

Recommended Posts

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
  • Like 3

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.

×