Help using git!
Kinda in usage order?
- Ask git what files need to be sent-off.
- Ask git to list all the branches, and indicate the one you're working on.
git add [path]
- Tell git to add changed file to be sent off to repo.
git commit -m "[message]"
- Commit all files in staging and add a message describing the changes.
git push origin [branch]
- Sned your changed to the git repo., where
[branch]is the name of the branch your'e working on. Use master for the main one, otherwise the name is up to you!
- Repo / Repository
Setting-up A New Repository
We do this via the command line. So open a terminal, or cmd if you're using Windows.
git config user.name [username]to add your username (can be whatever), and
git config user.email [emailaddress]to add the E-mail address you use to log-in to Github.
- (If you want to add SSH or GPG keys you should generate them now and add them via the web interface).
- Move to the directory where you'll be keeping your project.
git initto initialise the repo.
- Create a readme file and a .gitignore file.
- Your readme can be plain text or markdown, and should have a little info about the project. You'll have seen a bunch if you've visited Github, they're shown by default when you view a repo's page.
- The gitignore file tells git what you don't and/or do want included in your repository. For example you don't want to make private data like address books and SSH keys public!
git statuswill tell you what files you need to send-off to your repo.
git add .adds everything in your work directory to the queue to go to the repo (called staging). Instead of using a
.you can do it for individual files by entering their location.
git commit -m "[message]"where
[message]is a brief description of what you're changing.
- Next you'll need to do some stuff in your browser. Go to Github and create a new empty repository, then find and copy the 'remote repository URL'.
(You can do this from the CLI too, but you have to use Github's API and it's kinda clunky)
git remote add origin [remote repository url]to add the location.
git push origin masterwill send off all your changes D:
You can add certain dotfiles (filenames that start with a dot, they're a Unixy thing) to tell git to do certain things with your project. The most common is .gitignore, which tells git to ignore certain files and folders in your working directory.
It's a little bit fiddly to make dotfiles on windows, but you can do so in the command prompt. Either:
NUL> .gitignoreto create a new file.
REN [existing file] .gitignoreto rename a file you've already made.
To open a command prompt at your current location in Windows Explorer just type
cmd and hit
Enter in the location bar. You can jump to the location bar quickly with either
The .gitignore file is a list of files and directories that will not be uploaded to Git.
They can live multiple places, so you can exlude things globably, or per-project.
# comment *.ext file/path/ directory/ [Cc]ase
I like to start mine with
/* which excludes everything, then tell it exactly what I do want added by prefacing the file and directory names with a
Ignoring everything first, rather than ignoring everything individually was just the method that invloved less typing :) Different methods work better depending on your project and how you set up your directories :)
/* !.gitignore !.readme.md !index.html !styles/
Specific useful things to ignore
So for Unity game you probably want to ignore those .pdb files.
# Visual Studio / Unity *.pdb # Temp files *~
I just use the .editorconfig so when people view the files through Github's web interface the tabs look right, but you can set other stuff like line ending and character encoding in there too. Not sure if these files work with git generally. They are also common in text editors, perhaps the one you're using :)
root = true [*] indent_style = tab indent_size = 4
[*] is specifying which files to apply the arguments too (so you can enter specific extensions with, say:
- Oh shit, git! - Cures for tricky git problems.