the practice of tracking and managing changes to software code
- undo changes
- simplify collaboration
- look at previous versions
unnecessary comments in code
for (int i = 1; i < Ntr; i++) {
if (radius > turn_rad[i - 1] && radius <= turn_rad[i]) {
// for(int j = 1; j < Nh; j++) {
// if (theta < heading[j-1]) {
// // cout << "I" << i << endl;
// // cout << "J" << j << endl;
// q11 = torque_in[i-1][j-1];
// q12 = torque_in[i][j-1];
// q21 = torque_in[i-1][j];
// q22 = torque_in[i][j];
// // torque_out = sqrt(q22 - q12) * q22/q11;
// torque_out = abs(sqrt(q22 - q12) * q22/q11);
// cout << "T_Out:" << t_out << endl;
// }
// }
q11 = torque_in[i - 1][0];
q22 = torque_in[i][0];
torque_out = q22 / q11;
}
}
git
is a good version control tool
it is a command line utility
download from https://git-scm.com/downloads
make sure to enable
- Git on PATH (for Git Bash and CMD integration)
- CRLF Normalization
- MinTTY
git
associates your name and email with every change you make
inside a terminal:
$ git config --global user.name "Your Name"
$ git config --global user.email "youremail@domain.com"
a folder containing your code
every git repo contains a .git
folder
it stores all of your changes, don’t mess with it (manually)
$ git init
*inside an empty directory
step by step:
$ mkdir [folder_name]
$ cd [folder_name]
$ git init
$ git clone [path]
creates a new folder in your current directory
$ git clone [path] [destination]
clones the repo at destination
path can be:
- a repository on your computer
$ git clone ./path-to-existing-repo ./new-clone
- a link to a remote repo
$ git clone https://github.com/github/training-kit.git
*clones to ./training-kit
git
[subcommand]
[options]
tells you the status of your repository
*can tell you what to do next
collect related changes, put them on a stage
document these changes file-by-file, line-by-line
a commit stores
- a descriptive comment
- metadata
- changed lines
- commit id
inside the new repo you created with git init
, create README.md
$ touch README.md
add some content to this file via your text editor, save it.
$ git status
will tell you about the changes to your file
on branch master
no commits yet
untracked files:
(use "git add <file>..." to include in what will be committed)
README.md
nothing added to commit but untracked files present (use "git add" to track)
$ git add README.md
will “add” README.md
to the staging area
on branch master
no commits yet
changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README.md
$ git commit -m "Commit message"
will “commit” this change and store it permanently
*omitting the -m flag launches the default editor chosen by you during Git installation
[master (root-commit) 04e48d4] Initial Commit
1 file changed, 3 insertions(+)
create mode 100644 README.md
running git status
again will tell you the updated status of your repo
on branch master
nothing to commit, working tree clean
- Create changes (add/edit/remove)
$ git status
$ git add [filename]
$ git commit -m "Meaningful commit message"
- Repeat
*more parts coming soon!
unstages [file]
removes unstaged changes
git checkout .
removes ALL unstaged changes
shows unstaged changes (file-by-file, line-by-line)
git
is only as good as your commits
Write in present tense, imperative mood
Ex:
- Add README with title and summary
- Rewrite presentation section on commit messages
*commits should sound like commands
try to combine multiple related changes into one commit
making inefficient commits causes problems later
commits are checkpoints, you can revert them
good commit history:
- Implement navbar component
(contains changes including navbar styling and structure)
bad commit history (and commit messages):
- navbar
- sorry
- navbar styles
- typo
*bad commits clutter up your git history
Github is a cloud-based git
repository hosting service
there are several others: Gitlab, BitBucket, self-hosted Git instances
sign up at https://github.com/join
why Github?
- host your code online
- extra collaboration tools
- large developer community
a Github repo is simply a git
repo on a server
we can:
a. use git
on a terminal
b. interact through the site itself (via a browser)
- Go to https://github.com/new
- Provide a name and description
*don’t initialize the repo with README (for now)
- copy the
git
URL
https://github.com/yourname/repo.git
$ git clone [copied_url_path]
$ cd [repo_name]
inside your local repo
git remote add origin [copied_url_path]
copy the contents of your local repo to the cloned repo
you will need to recreate your commits
the .git
directory stores ALL info related to your project, ∴ different .git
== no commit/history
*esp useful when things go wrong
syncs your remotes
$ git push -u [remote] [branch]
git push -u origin main
pushes changes from your local main branch to the remote repo (aka origin)
git push
remembers your remote
$ git fetch
- Create changes (add/edit/remove)
$ git status
$ git add [filename]
$ git commit -m "Meaningful commit message"
- Repeat
$ git push