edit-article
Home
Up
Delete
Article Name:
Article Description:
] LIST of common git commands, brief description, example command
Chapter ID/Name:
Status:
Write
Writing
Written
Add Photo:
Owner ID:
Content:
use HTML
Edit Content
<h1 style="text-align: center;">common git commands</h1> <h2>[WHAT]</h2> <ol> <li>] LIST of common git commands, each with a brief description, example command</li> </ol> <h2>[WHY]</h2> <ol> <li>] quick reference</li> </ol> <h2>[WHERE]</h2> <ol> <li>]</li> </ol> <h2>[WHEN]</h2> <ol> <li><strong>[2015-06-22]</strong></li> <ol> <li>] -v-001 - examples list pulled from main overview article, SECTION how to, replaced with link to this article</li> </ol></ol> <h2>[EXAMPLE]</h2> <ol> <li><strong>] USE "git init"</strong> - in your local "working directory"</li> <ol> <li>] to create a local git repository,</li> <li>] a repository is a hidden directory where git operates </li> </ol> <li><strong>] USE "git status" - to get status, example below</strong></li> <ol> <li>] # on branch master</li> <li>] # initial commit</li> <li>] # nothing to commit (create/copy files and use "git add" to track)</li> </ol> <li><strong>] CREATE or COPY files(your projects code) into the "working directory"</strong></li> <ol> <li>] ...</li> </ol> <li><strong>] USE status - example below, now shows files that have been added to the working directory</strong></li> <ol> <li>] # on branch master</li> <li>] # initials commit</li> <li>] # untracked files</li> <ol> <li>] file.cs</li> <li>] file2.cs</li> <li>] ...</li> </ol></ol> <li><strong>] USE "git add {filename} " - to include what will be committed </strong></li> <ol> <li>] git add file.cs</li> </ol> <li><strong>] USE status </strong> </li> <ol> <li>] # changes to be committed</li> </ol> <li><strong>] USE git rm --cached {file.cs} </strong></li> <ol> <li>] to remove file from what wil be committed</li> </ol> <li><strong>] USE git commit -m "description of change"</strong></li> <ol> <li>] to commit files that have been added to the repository</li> </ol> <li><strong>] USE git add with wildcards to add multiple files</strong></li> <ol> <li>] git add '*.txt'</li> </ol> <li><strong>] USE git log</strong></li> <ol> <li>] a journal that remembers all the changes we've committed so far, in the order we committed them.</li> </ol> <li><strong>] EXAMPLE git log</strong></li> <ol> <li>] commit b652edfd888cd3d5e7fcb857d0dabc5a0fcb5e28</li> <li>] Author: Try Git try_git@github.com</li> <li>] Date: Sat Oct 10 08:30:00 2020 -0500</li> <li>] Description: " feature 223 - hilight on change"</li> </ol> <li><strong>] ADD remote repositories</strong></li> <ol> <li>] We've gone ahead and created a new empty GitHub repository for you to use with Try Git at <code>https://github.com/try-git/try_git.git</code>.</li> <li>] To push our local repo to the GitHub server we'll need to add a remote repository</li> <li>] This command takes a <em>remote name</em> and a <em>repository URL</em>, which in your case is <code>https://github.com/try-git/try_git.git</code>.</li> </ol> <li><strong>] USE git remote add origin https://github.com/try-git/try_git.git</strong></li> <ol> <li>] Git doesn't care what you name your remotes, but it's typical to name your main one <code>origin</code>.</li> <li>] It's also a good idea for your main repository to be on a remote server like <a href="http://github.com/" target="_blank">GitHub</a> in case your machine is lost at sea</li> </ol> <li><strong>] USE git push -u origin master</strong></li> <ol> <li>] Pushing Remotely - The push command tells Git where to put our commits when we're ready, and boy we're ready.</li> <li>] So let's push our local changes to our <strong>origin</strong> repo (on GitHub).</li> <li>] The name of our remote is <code>origin</code> and the default local branch name is <code>master</code>.</li> <li>] The <code>-u</code> tells Git to remember the parameters, so that next time we can simply run <code>git push</code> and Git will know what to do.</li> </ol> <li><strong>] USE git pull origin master</strong></li> <ol> <li>] Let's pretend some time has passed. We've invited other people to our github project who have pulled your changes, made their own commits, and pushed them.</li> <li>] We can check for changes on our GitHub repository and pull down any new changes by running: git pull origin master</li> </ol></ol> <h2>[REFERENCE]</h2> <ol> <li><strong>] BOOK - <a href="/view/chapters?id=263" target="_blank">git started</a></strong></li> <ol> <li>] # 2459 - <a href="/view/article?id=2459" target="_blank">table of contents</a> - a guide to learning git for noobs</li> </ol> <li><strong>] <a href="https://try.github.io/levels/1/challenges/1" target="_blank">interactive git tutorial</a></strong></li> <ol> <li>] # # - you can practice these commands in a simulated environment, a tutorial by</li> </ol></ol> <h1 style="text-align: center;"> </h1>