Guide:Git: Difference between revisions
(Working on Basics section-repo set, useful commands. Note on .editorconfig being a Github thing. Added some .gitignore example) |
m (→See Also: Removed link to Distribution:Git) |
||
Line 111: | Line 111: | ||
==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. |
Revision as of 21:20, 13 June 2021
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]
- 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!
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 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
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
See Also
- Oh shit, git! - Cures for tricky git problems.