joshmrallen
|
Complete Flatiron School Prework by...
Star this Commitment
Day 6 of 6
joshmrallen commits to:
Work on Flatiron School Prework for at least 8 hours a day, childcare permitting (sometimes I need to do stuff for the baby).
6
0
No more reports due
|
My Commitment Journal
joshmrallen
March 6, 2020, 6:15 PM
|
|
Notes/Report from Thursday 3/5 Git continued! Goals: * copy a repository to your local machine with: git clone * list remotes with git remote * duplicate other ogranizations' repositories into your own via GitHub with the "Fork" button Oh wow, I didn't realize Git was so widespred. Examples of what people use Git to track versions of are: Star Trek Fan Fiction, resumes, Ruby Code, JavaScript code, PhD theses, etc. So you can use Git with non-programming stuff. That's awesome and of course makes a lot of sense. I wish I had known better. I could have used this in my last few jobs haha This lesson will show how we can get others' repositories in addition to what we learned about creating our own repositories in the last lesson. Copy a repository to you computer with git clone repository source/creator must have their local repository mirrored onto the internet. This also means they have created a remote repository -- a copy of their local repository, but on the internet. What we clone with git clone is that remote repository. Example given is cloning the ReactJS framework -- used openmw repository instead 1. go to https://github.com/facebook/react 2. Click on green "Clone or download" button on the right 3. When box pops up, click the blue link that says "Use SSH" as the url type 4. Click "Copy to clipbaord" button 5. Open Terminal 6. put in the git clone command with the url we copied as its argument * git clone [email protected]:facebook/react.git * i know this is an example, but it says I don't have permission * this link to the github documentation really helped * https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent * wow, I just cloned the openmw repository. Maybe I can help contribute at some point. this is amazing * I had to set up an ssh key for my computer and then save it in my github account * Now I'm able to clone any repository List remotes with git remote * git remote - will return 'origin' * git remote show origin * shows the url where the repository came from origin is the name assigned to the address url that's fetched -- this url happens to be the same ssh url you copied in the first place * when you clone, the remote repository automatically sets up a remote name called 'origin' Create an online duplicate of organizations' repositories on GitHub by using the "Fork" button * this creates an online version for your use that's only accessable online * shows the location of the original Difference between clone and fork: * clone makes a local version on your computer * fork makes an online duplicate in your account and has the ability to update the master branch Licensing * original authors often include license information regarding how you can use their repository * so check carefully before you puclish, sell, or distribute any material you've forked, cloned and modified Pushing Code with Git * create a remote repository on GitHub * go to github.com/new * enter name * no need to intialize with README or add .gitignore or license (not sure why these are necessary options yet, but I did follow one tutorial in the past in order to create a new directory. forgot what it was I was working on though) * click the green "Create repository" button * see the "Quick setup" page * Make sure SSH option is selected * Click "Copy to Clipboard" icon next to the repo url * this is basically git init, online, aka remote * connect a local repository to a remote repository * get your local repository ready with git add <filename> and git commit -m "comments" * set the destination of a repo with git remote * make sure you copied the path for the remote online on GitHub -- this will be the url for your repository * default nickname for remotes is 'origin' * this way you don't have to type the long url over and over again -- this nickname is for convenience and can be anything you want, not just 'origin' all the time * in Terminal, make sure you're in the repository directory and type: * git remote add origin <remote ssh path url you copied online> * view the remote using 'git remote -v' * -v is for "verbose" * send code to the remote repo with git push * this command takes two arguments * name of the remote repo: origin in this case * name of the remote branch you want to send code to -- master (default branch) * in Terminal * git push -u origin master * -u is a flag that you only use the first time with 'origin master' as arguments -- it saves the remote repository as the default push destination * now whenever we want to push after this, we just use 'git push' and it will automatically send to the correct destination * awesome! this allows us to backup really easily, whether we're writing a book or creating a game or contributing to a project * it said "more on branching" later. * I assume instead of 'master', we put the name of the branch we want it to go to. Git Basics Lab! * Understand how to complete labs on Learn * Apply what you've learned about Git version control * Initialize a new Git repository * Stage and commit new content * Create a remote repository on GitHub * Connect the newly create local repository with the remote on GitHub Done! More practice basically. Getting the hang of using git, creating local repositories, remote one, and connecting them and pushing, and basically enjoying the power of GitHub. Amazing. Now I can contribute to openmw! But I think it might be in C++, which I only kind of know haha This next section will talk about branching and conflicts: Git Workflow Understanding Branches * What's a git branch? * a version you "branch" off of the master and work on separetely without affecting the "parent" branch * command: git branch will show all local branches * local branch * branch that only we (the local user) can see and exists only on our computer * git branch will show all local branches * remote branch * branch stored in a remote repository hosted on a server or service like GitHub * git branch -a * shows all the remote branches that git knows about * output of this command will be all the branch names that start with 'remotes/' * remote tracking branches * local copy of a remote branch * gets created when you push to a remote repository * allows you to sync or update by using git fetch * local tracking branches * a local branch that is tracking another local branch * most often, the local branch is tracking a remote tracking branch (which is tracking a remote branch) * explanation: * if a project collaborator has a branch that you want to work on too, they push their local branch to the repository as a branch -- let's call it my-friends-branch * Back at your own computer, open terminal and run the command: git fetch * this will refresh information from the remote repository in your clone. * this will also tell you that there's a new remote branch available (that your friend made), called origin/my-friends-branch * In Terminal: run the command, git checkout origin/my-friends-branch which will: 1. establish a remote tracking branch called: remotes/origin/my-friends-branch that points to origin/my-friends-branch 2. establish a local tracking branch, my-friends-branch, that tracks remotes/origin/my-friends-branch 3. put you on the local tracking branch, my-friends-branch * Now, when you make changes to the local tracking branch (my-friends-branch) and git push your changes, git will send your change to the remote repository so that your collaborators can get your change and build on it. * Once ready, your team can merge my-friends-branch to the master. Branching * Create a branch * git branch new-branch-name * if we don't specify a new name, it will list the branches that exist (master and any others that exist) * doing this will show an asterisk, *, next to master * this indicates which branch we're on * git checkout new-branch-name * this will put you "on" the branch you specify (new-branch-name in this case) * run git branch to confirm you've "moved" * git checkout -b new-branch-name * create a new branch and move onto that branch in a single command. (-b flag) * git checkout other-branch-name * move to any branch we specify * git checkout - * moves to the previous branch we were on (dash '-' is important here) * Add and commit changes * git log * shows a log of commits with id, branch, author, date * git status * most often used command - shows you what changes have been staged or added to commit * git add -p * review changes in chunks * git will guide you through each "chunk" and confirm whether to stage or not to stage the chunk * git add file-name * use if we know we want all the changes in the specified file, not individual chunks * git add . * this is 'add' and a dot '.' * use for all the changes in all the files in our current directory * git add images/. * this is the folder name, plus forward slash /, plus dot '.' * stages all the changes to all the files in a specified sub-directory * in this example, the subdirectory is 'images' * Careful with the dot * easy to accidentally commit something we didn't mean to * Developers say "commit small, commit often" * git commit -m "message" * -m is for message * limit to 50 characters * explain briefly what's changed * commits everything that's been staged for the current branch * no flag will open your system's editor (pico in my case) so you can log more information for more significant commits (changes, motivations, bug report URLS, and more) * by default, git will reach for the 'vim' editor * you can configure Git to use the Atom editor * git config --global core.editor "atom --wait" * Push a branch * just like we covered in the previous lesson: * git push -u origin new-branch-name * first time only when pushing the branch * after this, for this branch, you just have to use git push (-u saves origin new-branch-name) realized I can look up git commands easily by referencing them in the terminal with git man And also here: https://git-scm.com/docs/user-manual.html Remote * Get branch updates from remote * git fetch remote-name * Merge branches * git merge other-branch-name * when you want to merge another branch with the one you're currently working on * merge a branch to the master branch: * git checkout master * moves you back to master branch * git merge other-branch * merges other-branch with the branch you're currently on (master in this case) * Delete branches * git branch -d branch-name * -d stands for --delete * deletes the local branch only if you have already pushed and merged it with your remote branches * specify the branch name * git branch -D branch-name * -D stands for --delete --force * deletes the branch regardless of its push and merge status. * be careful with this one * git push <remote_name (most likely origin)> --delete <branch-name> * deletes a remote tracking branch * git branch -a to see all remaining remotes * Fetch and update the local branch in one step * original steps were to git fetch origin, then git merge origin/tracking-branch-name * git pull origin/tracking-branch-name * does this all with the same command * have to be on our local tracking branch * or just git pull if you're already 'on' the local tracking branch * git will assume you mean "the branch of the same name" at origin example of merge: $ git merge other-branch $ git merge origin/idea-my-friend-had $ git merge my-startup/time-travel-engine git-diff commit1 commit2 copy the first 7 digits of each commit id this will show us the difference between previous commits and current work git reset use when you undo a commit that you have not pushed yet git reset --soft HEAD-1 undoes the last commit git reset --soft HEAD-3 undoes last 3 commits number indicates the number of commits we want to go back by "The --soft tag keeps the changes we've made since last commit in our working state so that we can fix, add to or remove them manually. If we know we want to clear those changes entirely, we can use the --hard flag instead. Check the documentation to see all the ways to customize your command." git checkout . dot '.' will clear unwanted changes e.g., if you reset when you didn't mean to, type git checkout . to get back to the state before that git reset was run or a specific file (not a branch name): git checkout filename.html this will wipe all changes to the file and revert it to the last committed state, but keep all the other changes we made in our working state. Merge Conflicts * identify * merge conflicts happen when competing changes are made to the same line of a file * or when one person edits a file and another person deletes the same file * open the file and you'll see: * ========= * this separates the two conflicting changes * <<<<< content >>>>>>> * edit the content within these angle brackets * resolve * mark the file as resolved by executing git add filename * then commit with a message indicating the conflict resolution * revert * git merge --abort * reverses any merge at any time * always reset by getting the commit number from git log, then resetting with git reset -- hard <commit number> Merge Conflicts Lab 1. Make sure you have all three branches 2. Switch to the master branch 3. Merge Doc's branch into the master branch. This will merge "cleanly" 4. Merge Marty's branch in. This will not merge cleanly due to a "merge conflict" 5. Fix the merge conflict 6. Delete Doc and Marty's branches on your computer 7. Verify that Doc and Marty's branches have been integrated to your local master branch. |
|
.