{"id":48,"date":"2019-10-22T14:24:47","date_gmt":"2019-10-22T14:24:47","guid":{"rendered":"http:\/\/metajack.org\/blog\/?p=48"},"modified":"2019-10-22T14:24:47","modified_gmt":"2019-10-22T14:24:47","slug":"basic-git-usage","status":"publish","type":"post","link":"https:\/\/metajack.org\/blog\/2019\/10\/22\/basic-git-usage\/","title":{"rendered":"Basic git usage"},"content":{"rendered":"\n<p>Assuming you have already cloned a repository, the best place to start is with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git status<\/code><\/pre>\n\n\n\n<p>This will show the current state of the files including the branch you are on and any untracked changes. If you&#8217;ve come back to a project after a few days off, this will remind you where you are (which branch) and what you were doing (un-committed changes and diffs).<\/p>\n\n\n\n<p>&#8216;git status&#8217; may show modified files, such as:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>On branch master\nYour branch is ahead of 'origin\/master' by 3 commits.\n  (use \"git push\" to publish your local commits)\n\nChanges not staged for commit:\n  (use \"git add &lt;file>...\" to update what will be committed)\n  (use \"git checkout -- &lt;file>...\" to discard changes in working directory)\n\n\tmodified:   ..\/..\/..\/src\/apps\/sequencer\/engine\/generators\/RandomGenerator.cpp\n\nno changes added to commit (use \"git add\" and\/or \"git commit -a\")<\/code><\/pre>\n\n\n\n<p>To find out what is different in your changed files, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> git diff ..\/..\/..\/src\/apps\/sequencer\/engine\/generators\/RandomGenerator.cpp<\/code><\/pre>\n\n\n\n<p>If your diff output is formatted incorrectly (escape codes instead of colors), try:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git config --global core.pager \"less -R\"<\/code><\/pre>\n\n\n\n<p>To show all branches:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git branch -a<\/code><\/pre>\n\n\n\n<p>To create a new branch:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git checkout -b &lt;NEW BRANCH NAME><\/code><\/pre>\n\n\n\n<p>To change to a new branch:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git checkout &lt;branch name here><\/code><\/pre>\n\n\n\n<p>To change back to the &#8220;default&#8221; branch :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>check checkout master<\/code><\/pre>\n\n\n\n<p>To delete a branch:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git branch -d &lt;branch_name><\/code><\/pre>\n\n\n\n<p>To commit your changes<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git commit -m \"comment here\"<\/code><\/pre>\n\n\n\n<p>Upload your changes to github<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git push --set-upstream origin &lt;your-branch-name-here><\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Assuming you have already cloned a repository, the best place to start is with: This will show the current state of the files including the branch you are on and any untracked changes. If you&#8217;ve come back to a project after a few days off, this will remind you where you are (which branch) and &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/metajack.org\/blog\/2019\/10\/22\/basic-git-usage\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Basic git usage&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[7,9,8],"class_list":["post-48","post","type-post","status-publish","format-standard","hentry","category-programming","tag-git","tag-guide","tag-tutorial","entry"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/posts\/48","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/comments?post=48"}],"version-history":[{"count":6,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/posts\/48\/revisions"}],"predecessor-version":[{"id":70,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/posts\/48\/revisions\/70"}],"wp:attachment":[{"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/media?parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/categories?post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/tags?post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}