Created: 2022-10-06 Thu 19:48
the practice of tracking and managing changes to software code
filename-based
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
?
git
is a good version control tool
it is a command line utility
(but can be used via GUI clients)
git
download from https://git-scm.com/downloads
make sure to enable
बिना किसी…
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"
step by step:
mkdir [folder_name]
cd [folder_name]
git init
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 clone [path]
creates a new folder in your current directory
$ git clone [path] [destination]
clones the repo at destination
path is usually a git repo link:
a link to a remote repo
$ git clone https://github.com/github/training-kit.git
it can also be a repository on your computer
$ git clone ./path-to-existing-repo ./new-clone
git
[subcommand]
[options]
tells you the status of your repository
*can tell you what to do next
a commit stores
inside the new repo you created with git init
, create README.md
$ echo "Hello world!" > README.md
$ 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
[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
$ git status
$ git add [filename]
$ git commit -m "Meaningful commit message"
*more parts coming soon!
git
is only as good as your commits
Write in present tense, imperative mood
Ex:
*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:
Update Navbar component fixes #42 - add border-radius - fix bug around mobile view
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?
a Github repo is simply a git
repo on a server
we can:
git
on a terminal
*don’t initialize the repo with README (for now)
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
$ git status
$ git add [filename]
$ git commit -m "Meaningful commit message"
$ git push
Figure 1: branches allow you to work on multiple features/fixes simultaneously
main
/ master
: git’s default branch
HEAD
: alias to current branchseveral approaches
assuming working on some issue #53
$ git branch iss53 $ git checkout iss53
OR
$ git checkout -b iss53
add file, commit file
go back to continuing work on master
$ git checkout master
…
now there is some urgent issue, new fix required
$ git checkout -b hotfix
resolve bug, commit changes
go back to master
$ git checkout master
merge master to hotfix
$ git merge hotfix
master is now on hotfix (HEAD = master == hotfix)
hotfix no longer required, can safely delete hotfix
$ git branch -d hotfix
continue working on iss53
$ git checkout iss53 # make changes, add commits
$ git checkout master $ git merge iss53
such pain, much wow
if you changed the same part of the same file differently in the two branches you’re merging, Git won’t be able to merge them cleanly
Git does not know which change to keep
ergo, MeRgE CoNFliCts - Git asks you which change to keep
<<<<<<< HEAD:index.html <div id="footer">contact : email.support@github.com</div> ======= <div id="footer"> please contact us at support@github.com </div> >>>>>>> iss53:index.html