Git Commands
- git init: Initializes a git repo. Should only be done once, and NEVER inside a directory that is already within a git repo.
- git add -A: Prepares all files in the current directory (and inner directories from here) to be updated/added to git the next time you commit. files will not be modified if you commit without this!
- git commit -m "Your Message Here"Commit allows you to return to your directory in the current state at later times. It also sets it up so that you can actually submit your assignment. You can only submit what you committed!
- git remote add NAME_HERE DIRECTORY_HERE: Links up a remote repository address (DIRECTORY_HERE) to an alias (NAME_HERE). Saves you the trouble of typing out the whole directory address every time you need to pull from there.
- git pull (NAME_HERE or DIRECTORY_HERE) master: Pulls the files committed from the NAME_HERE or DIRECTORY_HERE location (whichever you typed) into your current directory. (You will only pull from master branches in our class for the assignments)
- git branch BRANCH_NAME: Creates a branch from the current branch, which means that anything you do here will not affect the other branches until you merge them together. (Can be useful for things like software updates, or rewrites that may break everything)
- git checkout BRANCH_NAME: Switches your active branch to BRANCH_NAME branch. If you made modifications to the current branch, you will need to commit the changes made or revert the branch back to the way it was before moving to BRANCH_NAME branch.
- git merge BRANCH_NAME: Merges the branch BRANCH_NAME into current one, so that the current branch gets updated with things in branch BRANCH_NAME. You can still access branch BRANCH_NAME which should be unmodified by the merge.
- git tag LABEL: Tags the previous commit with the LABEL so that you can access that commit easier. You can see which commit it was by typing git show LABEL. If you want to push to a directory, you must push AFTER adding the label.
- git push --tags (NAME_HERE or DIRECTORY_HERE) master: When you push, you send the changes to your git repo to the NAME_HERE or DIRECTORY_HERE depending on what you typed, and you may need to verify yourself to successfully send the change. You can put any branches other than master, but master is the one you will usually send. --tags will tell git to send the tags, which it will not do by default.
- git show TAG_HERE: Shows the commit associated with a given tag.
- git checkout -b BRANCH_NAME COMMIT_ID: This command will give you a new branch named BRANCH_NAME that is your git commit respective to the COMMIT_ID.
Please remember that we are teaching you git for your own benefit! Git is used in many companies and researches. Getting acquainted with it will only help you!