PlaceholderGames / 2ndYearHelpDesk

Where the important help requests and general questions get asked by CS2S561 students
0 stars 1 forks source link

Reminder on how to use github source code control #14

Open DoctorMikeReddy opened 6 years ago

DoctorMikeReddy commented 6 years ago

Start->cmd (the command line editor) cd to your Unity games folder, something like:

>f: >cd "My Documents" > cd "Unity Projects" >git init

which will set up the games folder for git source code control by adding a hidden .git folder

Now there are two options: 1) You have no local project folder

Each team already has a repo on PlaceholderGames at github, with the team members set as Admins, which includes two files: A .gitignore file that stops tracking of unnecessary files, and a Readme.md file. We need to set up the local repository to download those files and set up the hidden folder. In the command line window, in the Unreal Projects folder, type the following:

>git clone https://github.com/PlaceholderGames/name.git

where name is replaced with your repo name. This will create a local copy of the remote files (and hidden extra stuff). You will be prompted for your github username and password. After this, do the following:

>cd insert-game-folder

where insert-game-folder is the name of your repo. The folder will have been created by the 'clone'command. If you already have an Unityproject, you now need to copy all the files and folders from it into this newly created folder. Try to only have files that you need; for example, the standard assets that people often add to projects can take up a lot of unnecessary space, if you aren't going to use them. You can choose not to track these (we'll talk about this later), but for now try not to have assets in the project unless you are actually using them. It's probably best to delete these from the project inside Unity Editor. Once you have the files and folders you want to track (and upload to github) do the following:

> git status which will show in red the files and folders that have been added or amended. If you hare happy that all of these should be included in the project we need to add them officially:

>git add *

will add every file not specified in the .gitignore to be included in the project.

Before we commit the changes, which makes definite any changes or additions that you have made to the list of important files to keep on the server. This can always be reverted back to previous versions of the repo. However, unless you tell the server who you are, you might see a message explaining what username and email has been associated with the commit, and it not be you. You can change who is associated with the commit, or set your correct email

>git config --global user.email "your_email@example.com"

While you are at it, why not make sure your physical name is correct too

>git config --global user.name "Billy Everyteen"

All this will make sure that you are credited with the program changes that you have made. If (and it is a BIG if) you are committing changes done by someone else, make sure that you give them credit; see below. Now you can commit the changes, knowing that changes will be logged to you

>git commit -m "first commit" The '-m' bit means message, and the comment afterwards is historically 'first commit' only for the very first ever commit of the project. After that the message should be a description of what has been added, like "Fixed the bug on Level 5" or "Tightened up the Graphics on Level 3" and so on. Here is where you can make sure that you give credit, if commiting on behalf of someone else, with a message like "Committed changes made by Steve" etc.

If you have cloned the project, as described above, the following set up won't be needed, but if you have added a .gitignore to an existing non-tracked folder, you will need to set up where files come from and where they should go to:

>git remote add origin https://github.com/PlaceholderGames/name.git

where name of your repo is the name given when you created. This only needs doing once, as all it does is define 'origin' to be the remote server address.

Now we are ready to upload our actual project files to github, but PLEASE make sure all your files are saved and you have quit Unreal Engine first (!) or the files will be locked and strange things might happen:

>git push origin master

which will prompt you for your github username and password, but probably only once. This will upload any new or amended files that have been approved with the commit command to the remote server. If you get that right, there will be a load of files on the remote server after a few seconds or minutes. The 'master' bit I will explain later, when I talk about branches, but for now it is not necessary.

To check all this has been done properly:

>git status # A useful command at any time

This will show if you are up to date and what files differ between the local and remote repos. It will also show what branch you are on ('master' by default), of which we will talk more later, or possibly next year.

Once a local repo has been created, you can always download the latest version using the following command:

> git pull origin master

Any files that have been added or amended since you last worked on the project will be downloaded, unless there is a conflict where you have changed a file locally, and someone else has changed it and uploaded the change. This is called a conflict. For the most part, these conflicts can be resolved manually, and you can minimise conflicts by working cleverly; say, agreeing to work on separate map files (aka levels), as different files will never conflict with each other. However, it is not always possible to resolve conflicts automatically, such as when two people make changes to the same file or Blueprint. These will have to be compared - local versus remote - to manually adjust or decide which version should be kept.

Remember, when you make changes, you need to use 'git status' to decide what files have been added/amended, use 'git add' to select which (if not all) files should be tracked, 'git commit' with a suitable message after the '-m' flag, and 'git push' to upload the files to the remote repo.

WilliamAkins commented 6 years ago

I found this nice little website that lets you try out git commands on it, following a guide it provides. Might be useful to give an overview of git. https://try.github.io