{"id":27,"date":"2019-03-29T04:10:01","date_gmt":"2019-03-29T04:10:01","guid":{"rendered":"https:\/\/tailordev.co.uk\/?p=27"},"modified":"2019-03-29T04:10:01","modified_gmt":"2019-03-29T04:10:01","slug":"git-commands","status":"publish","type":"post","link":"https:\/\/tailordev.co.uk\/?p=27","title":{"rendered":"Git Commands"},"content":{"rendered":"\n<p><em>A li<\/em>st of commonly used Git commands<\/p>\n\n\n\n<h3>Getting &amp; Creating Projects<\/h3>\n\n\n\n<table class=\"wp-block-table\"><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>git init<\/code><\/td><td>Initialize a local Git repository<\/td><\/tr><tr><td><code>git clone ssh:\/\/git@github.com\/[username]\/[repository-name].git<\/code><\/td><td>Create a local copy of a remote repository<\/td><\/tr><\/tbody><\/table>\n\n\n\n<h3>Basic Snapshotting<\/h3>\n\n\n\n<table class=\"wp-block-table\"><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>git status<\/code><\/td><td>Check status<\/td><\/tr><tr><td><code>git add [file-name.txt]<\/code><\/td><td>Add a file to the staging area<\/td><\/tr><tr><td><code>git add -A<\/code><\/td><td>Add all new and changed files to the staging area<\/td><\/tr><tr><td><code>git commit -m \"[commit message]\"<\/code><\/td><td>Commit changes<\/td><\/tr><tr><td><code>git rm -r [file-name.txt]<\/code><\/td><td>Remove a file (or folder)<\/td><\/tr><\/tbody><\/table>\n\n\n\n<h3><a href=\"https:\/\/github.com\/joshnh\/Git-Commands#branching--merging\"><\/a>Branching &amp; Merging<\/h3>\n\n\n\n<table class=\"wp-block-table\"><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>git branch<\/code><\/td><td>List branches (the asterisk denotes the current branch)<\/td><\/tr><tr><td><code>git branch -a<\/code><\/td><td>List all branches (local and remote)<\/td><\/tr><tr><td><code>git branch [branch name]<\/code><\/td><td>Create a new branch<\/td><\/tr><tr><td><code>git branch -d [branch name]<\/code><\/td><td>Delete a branch<\/td><\/tr><tr><td><code>git push origin --delete [branchName]<\/code><\/td><td>Delete a remote branch<\/td><\/tr><tr><td><code>git checkout -b [branch name]<\/code><\/td><td>Create a new branch and switch to it<\/td><\/tr><tr><td><code>git checkout -b [branch name] origin\/[branch name]<\/code><\/td><td>Clone a remote branch and switch to it<\/td><\/tr><tr><td><code>git checkout [branch name]<\/code><\/td><td>Switch to a branch<\/td><\/tr><tr><td><code>git checkout -<\/code><\/td><td>Switch to the branch last checked out<\/td><\/tr><tr><td><code>git checkout -- [file-name.txt]<\/code><\/td><td>Discard changes to a file<\/td><\/tr><tr><td><code>git merge [branch name]<\/code><\/td><td>Merge a branch into the active branch<\/td><\/tr><tr><td><code>git merge [source branch] [target branch]<\/code><\/td><td>Merge a branch into a target branch<\/td><\/tr><tr><td><code>git stash<\/code><\/td><td>Stash changes in a dirty working directory<\/td><\/tr><tr><td><code>git stash clear<\/code><\/td><td>Remove all stashed entries<\/td><\/tr><\/tbody><\/table>\n\n\n\n<h3><a href=\"https:\/\/github.com\/joshnh\/Git-Commands#sharing--updating-projects\"><\/a>Sharing &amp; Updating Projects<\/h3>\n\n\n\n<table class=\"wp-block-table\"><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>git push origin [branch name]<\/code><\/td><td>Push a branch to your remote repository<\/td><\/tr><tr><td><code>git push -u origin [branch name]<\/code><\/td><td>Push changes to remote repository (and remember the branch)<\/td><\/tr><tr><td><code>git push<\/code><\/td><td>Push changes to remote repository (remembered branch)<\/td><\/tr><tr><td><code>git push origin --delete [branch name]<\/code><\/td><td>Delete a remote branch<\/td><\/tr><tr><td><code>git pull<\/code><\/td><td>Update local repository to the newest commit<\/td><\/tr><tr><td><code>git pull origin [branch name]<\/code><\/td><td>Pull changes from remote repository<\/td><\/tr><tr><td><code>git remote add origin ssh:\/\/git@github.com\/[username]\/[repository-name].git<\/code><\/td><td>Add a remote repository<\/td><\/tr><tr><td><code>git remote set-url origin ssh:\/\/git@github.com\/[username]\/[repository-name].git<\/code><\/td><td>Set a repository&#8217;s origin branch to SSH<\/td><\/tr><\/tbody><\/table>\n\n\n\n<h3><a href=\"https:\/\/github.com\/joshnh\/Git-Commands#inspection--comparison\"><\/a>Inspection &amp; Comparison<\/h3>\n\n\n\n<table class=\"wp-block-table\"><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>git log<\/code><\/td><td>View changes<\/td><\/tr><tr><td><code>git log --summary<\/code><\/td><td>View changes (detailed)<\/td><\/tr><tr><td><code>git diff [source branch] [target branch]<\/code><\/td><td>Preview changes before merging<\/td><\/tr><\/tbody><\/table>\n","protected":false},"excerpt":{"rendered":"<p>A list of commonly used Git commands Getting &amp; Creating Projects Command Description git init Initialize a local Git repository git clone ssh:\/\/git@github.com\/[username]\/[repository-name].git Create a local copy of a remote repository Basic Snapshotting Command Description git status Check status git add [file-name.txt] Add a file to the staging area git add -A Add all new [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[11,12],"_links":{"self":[{"href":"https:\/\/tailordev.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/27"}],"collection":[{"href":"https:\/\/tailordev.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tailordev.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tailordev.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tailordev.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=27"}],"version-history":[{"count":1,"href":"https:\/\/tailordev.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/27\/revisions"}],"predecessor-version":[{"id":28,"href":"https:\/\/tailordev.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/27\/revisions\/28"}],"wp:attachment":[{"href":"https:\/\/tailordev.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tailordev.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tailordev.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}