-
Notifications
You must be signed in to change notification settings - Fork 0
Git Basics and Resources
Git is not as scary as it seems I promise.
This is a great primer for beginners: https://github.com/cs-clarence/git-primer
Great info about branches: https://www.w3schools.com/git/git_branch.asp
assuming you’re using a cli (command line interface, the terminal):
-
git init
<- Makes an empty .git file in your current directory, so your version history can start getting tracked for this repository. -
git add [file path]
<- Adds the file to your records, or updates the version being tracked. Note that you can press tab to show what files match the path you’ve typed, and stop you from typing the full name forever -
git commit -m “Message”
<- Makes your additions official. This can be undone or rollbacked easily, but if you never commit you can’t get back old work! Don’t be afraid to commit liberally. -
git push
<- Puts your work up on the remote repo (assumingly on github). If this fails, it will tell you the reason (most likely that you don’t have a remote repo set up. Be not afraid! You can add it withgit remote add [repo link]
) -
git pull [link]
<- Pulls (fetches) all files from the remote repo (github) and updates your local repository (on your computer). If you do not include the link, it will assume you are pulling from your pre-configured remote repo. Implies a connection to your current project, and that you may change it. -
git clone [link]
<- Creates a new folder that contains the pulled repo and all its own git history. It will do this in the directory you’re typing it from. -
git branch [branch name]
<- creates a new branch of the repo -
git branch ← shows you what branch you’re on and the other branches you can swap to locally. Does not show all the possible remote branches if you haven’t pulled them.
-
git merge [branch name]
<- Adds everything from the selected branch to your current branch. However, before you do this, you should consider why the merge is needed, and the things that will be impacted. I recommend instead of using this command, do merges using the web gui, so you can review the exact files impacted and add comments more easily. You can also add a reviewer on web, so they can take a look at what will be impacted.
Github’s documentation on the topic is here: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/merging-a-pull-request
-
git checkout [branch name]
<- Moves you over to this branch. Does not take your work with you! Make sure you’ve committed. git status <- Tells you stuff like your working branch, the tracked files, the untracked files, the new changes, and things that will be added in your next commit.
-
Never. Never never never neverennevnernenrenvenrner push passwords, login info, or any private key. Please scrub your code of them or (even better) keep them in your environment variables.
-
Don’t push data or a large number of network weights. This takes a long time to upload and a long time to pull and will eventually have us pushing against storage limits of github. Use DeepGotData or Zendo Instead!~
-
Use a type of linter or pre-commit hooks, as provided by our template repo (link)
-
Commit often and commit with descriptive comments
-
Any major change (function written, new file, any file rewrite) should be committed with a comment of what you did.
-
At the end of the day, or just at the end of a session, I recommending pushing your work to a remote (just in case of a catastrophic blue screen of death).
-
Always pull before you push.
-
If working with a collaborator, on different but potentially similar parts of code, work on different branches.
-
Include a .gitignore, that makes sure you don’t track things like pycaches or any other compiled code. This can potentially cause issues when installing on different os’.
- Github supports something called ‘actions’. Which is basically just a script that’s triggered when you take a… get this… action on github.
- Main docs are here: https://docs.github.com/en/actions
- We have some of them included in the template repos! Check them out!
- They’re fantastic for automatically updating things, or automatically running tests.
- DeepBench
- DeepGotData
- DeepUtils
- Google Colaboratory
- Elastic Analysis Facility (EAF; Fermilab)
- Research Computing Center (UChicago)
- coming soon.