Guide:Git: Difference between revisions
(Working on Basics section-repo set, useful commands. Note on .editorconfig being a Github thing. Added some .gitignore example) |
(Tools section with linsk for downloading single directories fro mgithub) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 8: | Line 8: | ||
;<code>git add [path]</code> : Tell git to add changed file to be sent off to repo. | ;<code>git add [path]</code> : Tell git to add changed file to be sent off to repo. | ||
;<code>git commit -m "[message]"</code> : Commit all files in staging and add a message describing the changes. | ;<code>git commit -m "[message]"</code> : Commit all files in staging and add a message describing the changes. | ||
;<code>git push origin [branch]</code> : | ;<code>git push origin [branch]</code> : Send your changed to the git repo., where <code>[branch]</code> is the name of the branch you're working on. Use ''master'' for the main one, otherwise the name is up to you! | ||
===Glossary=== | ===Glossary=== | ||
Line 21: | Line 21: | ||
===Setting-up A New Repository=== | ===Setting-up A New Repository=== | ||
====Github==== | ====Github==== | ||
We do this via the | We do this via the {{jargon|CLI|command line}}. So open a terminal, or cmd if you're using Windows. | ||
# <code>git config user.name [username]</code> to add your username (can be whatever), and | # <code>git config user.name [username]</code> to add your username (can be whatever), and | ||
# <code>git config user.email [emailaddress]</code> to add the E-mail address you use to log-in to Github. | # <code>git config user.email [emailaddress]</code> to add the E-mail address you use to log-in to Github. | ||
# (If you want to add | # (If you want to add {{jargon|SSH|SSH}} or {{jargon|GPG|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. | # Move to the directory where you'll be keeping your project. | ||
# <code>git init</code> to initialise the | # <code>git init</code> to initialise the {{jargon|Repository|repo}}. | ||
# Create a ''readme'' file and a ''.gitignore'' file. | # 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. | #* 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. | ||
Line 67: | Line 67: | ||
I like to start mine with <code>/*</code> which excludes ''everything'', then tell it exactly what I do want added by prefacing the file and directory names with a <code>!</code> | I like to start mine with <code>/*</code> which excludes ''everything'', then tell it exactly what I do want added by prefacing the file and directory names with a <code>!</code> | ||
Ignoring everything first, rather than ignoring everything individually was just the method that | Ignoring everything first, rather than ignoring everything individually was just the method that involved less typing :) Different methods work better depending on your project and how you set up your directories :) | ||
<pre> | <pre> | ||
Line 79: | Line 79: | ||
===Specific useful things to ignore=== | ===Specific useful things to ignore=== | ||
====Unity==== | ====Unity==== | ||
So for Unity game you probably want to ignore those .pdb files. | So for [[Unity]] game you probably want to ignore those .pdb files. | ||
* https://gist.github.com/octocat/9257657 | * https://gist.github.com/octocat/9257657 | ||
Line 109: | Line 109: | ||
====See Also==== | ====See Also==== | ||
* [http://editorconfig.org/ editorconfig.org] | * [http://editorconfig.org/ editorconfig.org] | ||
==Tools== | |||
* [https://download-directory.github.io/ download-directory] and [https://minhaskamal.github.io/DownGit DownGit]<br>Web interfaces for downloading a single directory from a git repo, something Git doesn't support natively. I've found it useful for grabbing [[Guide:Assets#Samples|packs of audio samples]], for example. | |||
==See Also== | ==See Also== | ||
* [http://ohshitgit.com/ Oh shit, git!] - Cures for tricky git problems. | * [http://ohshitgit.com/ Oh shit, git!] - Cures for tricky git problems. | ||
* [https://leetusman.com/nosebook/git-for-artists Git For Misfits (and artists)] - Git guide not aimed at programmers. | |||
[[Category:CLI]] |
Latest revision as of 02:28, 16 December 2022
Help using git!
Basics
Commands
Kinda in usage order?
git status
- Ask git what files need to be sent-off.
git branch
- 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]
- Send your changed to the git repo., where
[branch]
is the name of the branch you're working on. Use master for the main one, otherwise the name is up to you!
Glossary
- Branch
- ...
- Commit
- ...
- Fork
- ...
- Merge
- ...
- Pull
- ...
- Repo / Repository
- ...
- Staging
- ...
Setting-up A New Repository
Github
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), andgit 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 init
to 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 status
will 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 master
will send off all your changes D:
Meta Files
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> .gitignore
to create a new file.REN [existing file] .gitignore
to 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 F4
or Alt+D
.gitignore
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.
Examples
# 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 involved 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
Unity
So for Unity game you probably want to ignore those .pdb files.
# Visual Studio / Unity *.pdb # Temp files *~
.editorconfig
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 :)
Example:
root = true [*] indent_style = tab indent_size = 4
The [*]
is specifying which files to apply the arguments too (so you can enter specific extensions with, say:
[*.{html,md}]
See Also
Tools
- download-directory and DownGit
Web interfaces for downloading a single directory from a git repo, something Git doesn't support natively. I've found it useful for grabbing packs of audio samples, for example.
See Also
- Oh shit, git! - Cures for tricky git problems.
- Git For Misfits (and artists) - Git guide not aimed at programmers.