forked from nzufelt/open_source_movement_csc630
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit.html
66 lines (66 loc) · 8.04 KB
/
git.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' >
<title>CSC630: The Open Source Movement</title>
<link rel='stylesheet' type='text/css' href='./assets/styles/main.css' />
<meta name='description' content='CSC630: The Open Source Movement, Phillips Academy Andover, Winter 2018'/>
<meta name='keywords' content='computer science, open source' />
<meta name='robots' content='index,follow' />
</head>
<body>
<div id='wrapper'>
<header>
<div class='gradient'></div>
<div class='content'>
<h1><a href='index.html'>CSC630: The Open Source Movement</a> // Git Cheatsheet <span class='right'><p>Phillips Academy Andover  ▪  Winter 2018</p></span></h1>
</div>
<div class='nav-wrapper'>
<nav>
<a href='assignments.html'>Assignments</a>
<a href='resources.html'>Resources</a>
<a href='git.html'>Git Cheatsheet</a>
<a href='essays.html'>Essays</a>
<a href="projects.html">Projects</a>
<a href="memes.html">Memes</a>
<a href='https://github.com/nzufelt/open_source_movement_csc630/' class='right'>On GitHub</a>
</nav>
</div>
</header>
<main class='three-column'>
<ul>
<li><a href='https://git-scm.com/docs/git-init'><code>git init</code></a> Create a new git repository in the working directory. Existing files will <i>not</i> be automatically added to the repository (i.e. they will not be tracked). If a git repository already exists in the working directory, it is reinitialized. More specifically, it creates the <code>.git</code> directory in the current directory with <code>objects</code>, <code>refs/heads</code>, and <code>refs/tags</code>. The reference <code>HEAD</code> will point to the new repository.</li>
<li><a href='https://git-scm.com/docs/git-clone'><code>git clone</code></a> This command clones a remote repository onto your local machine. It will create remote references for each branch in the repository. It will automatically configure <code>remote.origin.url</code> (for pushing) and <code>remote.origin.fetch</code> (for fetching).</li>
<li><a href='https://git-scm.com/docs/git-status'><code>git status</code></a> Tells you the tree and index status (i.e. whether you're ready to commit or not).</li>
<li><a href='https://git-scm.com/docs/git-add'><code>git add <filename></code></a> Adds the changed/created files to the index found in the workspace, to stage the content for its future commit.</li>
<li><a href='https://git-scm.com/docs/git-rm'><code>git rm <filename></code></a> Remove a file from git's index, and remove it from the working tree if it exists there.</li>
<li><a href='https://git-scm.com/docs/git-reset'><code>git reset</code></a> Resets all of the changes since the last commit match back to the last commit. The primary use is <code>git reset --hard</code>, which resets everything.</code></li>
<li><a href="https://git-scm.com/docs/git-commit"><code>git commit</code></a> Record your staged changes to the repository (<em>i.e.</em> the files you have added/modified/deleted) as a new tree object of your working copy, which points to its parent commit (if it's not the first). Finally, it points the current branch to your most recent commit. If you add the <code>-m <msg></code> flag, you can also leave a comment to detail your changes: <code>git commit -m "fixed all the bugs. lol jk, there's more"</code>
<img src="https://codewords.recurse.com/images/two/git-from-the-inside-out/8-a2-just-objects-commits-and-refs.png"/>
The Git tree after committing "a2" with parent commit "a1."
</li>
<li><a href="https://git-scm.com/docs/git-diff" target="_blank"><code>git diff</code></a> Displays changes between states in your repository. For example, changes between the working tree and the index or a tree, changes between the index and a tree, changes between two trees, changes between two blob objects, or changes between two files on a disk.</li>
<li><a href='https://git-scm.com/docs/git-log'><code>git log</code></a> Shows the commit history. The command will show the author of the commit, the date of the commit, and a commit hash that you can use a git checkout command on to view a detached head version of the repo.</li>
<li><a href='https://git-scm.com/docs/git-branch'><code>git branch <branchname></code></a> This command will create a new branch in the current repository, with the name <code>branchname</code>. Without specifying a branch name, it will list all branches.</p></li>
<li><a href='https://git-scm.com/docs/git-checkout'><code>git checkout</code></a> Change the workspace (<em>i.e.</em> the current files in the directory) to those located at the specified commit. In essence, moves 'you' (a.k.a. <code>HEAD</code>) to the commit. If you add the <code>-b</code> flag, it will create a new branch with the specified name: <code>git checkout -b <new_branch_name></code>.
<img src='./assets/images/git_cheatsheet/git_checkout.png'/>
</li>
<li><a href="https://git-scm.com/docs/git-remote"><code>git remote</code></a> Set, edit, and remove "remotes" (variables that hold urls to git repository). For example, instead of saying <code>git push [LONG URL] master</code>, you can say <code>git push [remote name] master</code>. The <code>git remote</code> command has subcommands you can use to manipulate remotes—<em>e.g.</em> to add a remote, use <code>git remote add [remote_name] [remote_url]</code>.</li>
<li><a href='https://git-scm.com/docs/git-push'><code>git push</code></a> Bring the remote up to date with your local copy, by updating the references (<code>HEAD</code>, <code>master</code>, etc.) on the remote using local references and sending objects that are present locally but not remotely.
<img src='./assets/images/git_cheatsheet/git_push.png' />
</li>
<li><a href="https://git-scm.com/docs/git-fetch"><code>git fetch</code></a> Downloads objects and refs from another repository. Fetch refs from one or more other repositories, along with the objects necessary to complete their histories.</li>
<li><a href='https://git-scm.com/docs/git-merge'><code>git merge <branchname></code></a> Adds the changes from the given commits into the current branch. Specifically, this command replays the changes made on the named commit (<em>i.e.</em> <code>git pull topic</code>) and records the result in a new commit. This command is used by <em>git pull</em> by default to incorporate changes from another repository.</li>
<li><a href='https://git-scm.com/docs/git-pull'><code>git pull</a> <remote_repo> <remote_branch></code>: Runs <code>git fetch</code> (with the given parameters) followed by <code>git merge</code> to merge retrieved branch heads into the current branch.</li>
<li><a href='https://git-scm.com/docs/git-cherry-pick'><code>git cherry-pick</code></a> Given one or more existing commits, apply the change each one introduces, recording a new commit for each. This requires your working tree to be clean (no modifications from the HEAD commit).</li>
<li><a href='https://git-scm.com/docs/git-stash'><code>git stash</code></a> Stash the changes in a dirty working directory away.</li>
<li><a href='https://git-scm.com/docs/git-rebase'><code>git rebase</code></a> All changes made by commits in the current branch but that are not in <upstream> are saved to a temporary area. This is the same set of commits that would be shown by <code>git log upstream..HEAD</code>; or by <code>git log 'fork_point'..HEAD</code>, if <code>--fork-point</code> is active; or by <code>git log HEAD</code>, if the <code>--root</code> option is specified.</li>
</ul>
</main>
<footer>
<p>Made with ❤ at Phillips Academy.</p>
</footer>
</div>
<script src='scripts/header.js'></script>
</body>
</html>