Initializing a new project with git.

Esteban Ibarra
6 min readMar 16, 2021

So to review, Git’s a method of archiving your work as well as having a method of branching your project into different areas to experiment with features you may want to implement in a safe environment before committing them to your main project. Committing files is like creating a savepoint in your project like a videogame. If your character or project dies, you can just start over from the last savepoint. Commits are a lifesaver!

So we’ve installed Git, registered our name and email, signed up to github and maybe bitbucket and we’re ready to go!

We’re going to continue using the terminal version of git because we’re just that awesome and we don’t need a front end like a total n00b! (Though it’s Ok if you want to use one because it works better for you, whatever works is valid! The important thing is you’re using git to protect your work.)

So first of all, let’s navigate to the directory where our game is stored at. You can do this in the normal window manager. I’ve navigated to mine in the MATE windows environment in Linux Mint.

As you can see at the top, the directory structure is massive, if we just opened up a terminal, we’de have to type it all! Fortunately, you can just right click and open a terminal from this spot, thank goodness!

DIRECTORIES:

as you can see I typed in LS, this is the same as dir for giving a directory of your folder.

say you wanted to change into another folder, like Temp, all you’de have to do is type cd temp. CD = Change directory

if I wanted to find all the directories that started with the letters ST, then I’d just have to type cd ST and hit tab and it will present to you any directory that starts with st.

if you wanted to go back up a level, just type cd .. (two periods)

GIT INIT

Notice that we are inside the actual unity project folder. This is where you’ll want to create your repository. Location is important here because depending on where you create your git repository, that’s where it will begin recording every change inside the folder. Since we’re working in Unity, we want to physically enter the folder that Unity creates for its project and initialize the repository there by typing “git init”

and now it tells us it’s done it. Now git will begin to track every change we’re making in our project!

Everything’s all set right? Let’s check our status by typing “git status”

uh oh, what are all those red lines? Whenever you see them, that means these files are not added or committed to the archive. This is done in a couple steps. You need to first stage the files for comitting, and then commit them. Why this extra step? Mainly for security. when you commit a file, it’s now effectively archived forever (until you maybe delete a branch, but that pretty much overrides the point of git in the first place)

But before we continue, let’s create our remote repository on github!

From your github page, there’s a beautiful green button with the word ‘new’ on it. Click on it to get your online repository going!

The process is simple enough, choose a name, add a description, and since this is a unity project, add the .gitignore for unity to skip the bloat and then hit the create repository button!

and there you have it! You’ve now created the online repository. there’s but one thing left to do and that’s hit that code download button on the right hand corner and copy the url onto your clipboards memory. we’ll be using it in a moment.

to connect our local to the remote repositories type

git remote add origin <paste the url you just copied from your github>

and you can verify you have it by typing git remote -v and if you’re successful, it will give you the fetch and push address.

We’re almost ready to put our project onto github! remember all those red files? we’re going to add them to the staging area to prepare them to being comitted by using the add command!

Word of caution, there can be merge conflicts. These can be avoided by first doing a pull from the server, then committing, then a push.

Also, because of recent changes, we need to manually change the name of master to main, git branch -m master main

we can verify the name change by just typing git branch.

Now we can begin to add our files!

git add <filename.ext>

But wait! There are too many files! No problem! Just use the period to add everything!

git add .

after a few seconds, type git status and you’ll get a listing of many green files which means they’re ready to be committed. then type git commit -m “description of what changes were made”

typing git push origin gets us a message:

“fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use

git push — set-upstream origin main”

So we’ll type that.

AND IT WORKS!!!

now commit it!

git commit -m “this is the initial commit of my awesome game!”

Remember to add a descriptive note to each commit so when you come back to it a long time later, you can easily see what changes were made.

We can verify this by going to our github page and voila! Our project is now connected to our remote github account! Now we have all the advantages of having a remote account like collaboration with others online, or showing off your programming talent!

You’ve now had a taste of pulling and pushing to a remote server, tomorrow, we’ll wrap things up with a few simple commands to commit and branch

--

--