There are 5 main commands you'll use with git.
git pull
- download any new changes made by other people from the shared repository on GitHub
git push
- upload any new changes that you made on your local repository to the shared repository
git add
- tell git which files are important (you must do this before each commit)
git commit
- permanently save any changes to files added with git add
. You can only git push
after you git commit
.
git status
- get info on the current status of your local repository (which files have been modified, commited, etc)
When you git clone
a project, git downloads the most up-to-date version of the project. Any time you're going to start making changes, you should git pull
to download recent updates made by other people. This ensures that you're working with the latest version of every file.
If you're not sure about the status of your current repository, you can check on the details with git status
. You can also use git log -5
(or any other number) to view the 5 most recent commits. They should match the most recent commits on GitHub. If you're missing a commit, then your copy of the project is out of date.
When you're going to make a change, it's usually best to follow these 5 steps:
git status
- make sure git says you have uncommitted changesgit add .
- tell git you want to commit every file. NOTE: if git asks you if you would like to force it to add files with -f, do not do this!git commit -m "Briefly explain the changes you made."
git pull
- check for new changes made since you started working. Resolve any conflicts if they arrise (best to discuss this with whoever made the conflicting commit)git push
- upload your commit to the shared repository.
git stash
- Sometimes when you try togit pull
, git will say that you've made changes even when you haven't (this can happen when you open Unity, which automatically makes a few changes). Usegit stash
to 'erase' any local changes so that you can successfullygit pull
. Changes 'erased' withgit stash
can be recovered later, if necessary.