{"id":1484,"date":"2021-03-18T14:49:46","date_gmt":"2021-03-18T14:49:46","guid":{"rendered":"https:\/\/dft.wiki\/?p=1484"},"modified":"2026-06-08T23:19:41","modified_gmt":"2026-06-09T03:19:41","slug":"working-with-github-repository","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=1484","title":{"rendered":"Working with Git Repositories in GitHub"},"content":{"rendered":"<p>First things first. Create an account and log in to GitHub [<a href=\"https:\/\/github.com\">Link<\/a>].<\/p>\n<p>Go to <strong>Settings &gt; SSH and GPG Keys &gt; Add SSH Key<\/strong>.<\/p>\n<p>Give it a meaningful name and paste your <span style=\"color: #ff0000;\"><strong>SSH Public Key<\/strong><\/span>.<\/p>\n<p>Create a <strong>New Repository<\/strong>. It can be public or private.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1488\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2021\/03\/Screenshot-from-2021-03-18-10-43-52.png\" alt=\"\" width=\"225\" height=\"199\" \/> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1489\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2021\/03\/Screenshot-from-2021-03-18-10-45-09.png\" alt=\"\" width=\"483\" height=\"239\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2021\/03\/Screenshot-from-2021-03-18-10-45-09.png 483w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2021\/03\/Screenshot-from-2021-03-18-10-45-09-300x148.png 300w\" sizes=\"auto, (max-width: 483px) 100vw, 483px\" \/><\/p>\n<p>It is always good to <strong>Add a README.md<\/strong> file.<\/p>\n<p>Add a description and instructions about the repo in the README.md file and save.<\/p>\n<p>Then click <strong>Download Code<\/strong>, select <strong>SSH<\/strong>, and copy the URL:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1490\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2021\/03\/Screenshot-from-2021-03-18-10-46-43.png\" alt=\"\" width=\"353\" height=\"238\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2021\/03\/Screenshot-from-2021-03-18-10-46-43.png 353w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2021\/03\/Screenshot-from-2021-03-18-10-46-43-300x202.png 300w\" sizes=\"auto, (max-width: 353px) 100vw, 353px\" \/><\/p>\n<p>On your Linux terminal, where you have the private key that matches the uploaded public key, run the following command to clone the repository:<\/p>\n<pre>git clone <strong>git@github.com:user\/private.git<\/strong><\/pre>\n<p>Pull changes from remote to local:<\/p>\n<pre>git pull\r\ngit pull --verbose<\/pre>\n<p>Set your Git identity so you can commit changes to your repositories:<\/p>\n<pre>git config --global user.email \"<strong>Your E-Mail<\/strong>\"\r\ngit config --global user.name \"<strong>Your Name<\/strong>\"\r\ncat ~\/.gitconfig<\/pre>\n<p>To set your identity for a specific repository only:<\/p>\n<pre>git config user.email \"<strong>Your E-Mail<\/strong>\"\r\ngit config user.name \"<strong>Your Name<\/strong>\"<\/pre>\n<p>Modify the text in the README.md file you cloned from the repository and save.<\/p>\n<p>Check the status of the local repository against the remote:<\/p>\n<pre>git status<\/pre>\n<p>Output:<\/p>\n<pre>...\r\n<strong>modified:<\/strong> README.md\r\n...<\/pre>\n<p>Check what changed:<\/p>\n<pre>git diff\r\ngit diff --staged\r\ngit diff --staged README.md\r\ngit diff --cached README.md \r\ngit diff file1.txt file2.txt\r\ngit diff COMMIT1-ID COMMIT2-ID\r\ngit --no-pager diff COMMIT1-ID COMMIT2-ID<\/pre>\n<p>Commit and push the changes to the remote repository:<\/p>\n<pre>git <strong>add<\/strong> README.md\r\ngit <strong>commit -m<\/strong> \"message about the update\"\r\ngit commit <strong>--amend<\/strong> -m \"Updating message for the previous commit\"\r\ngit add anotherFile.txt\r\ngit commit --amend <strong>--no-edit<\/strong>\r\ngit <strong>push<\/strong><\/pre>\n<p>Remove one file or all files from the staging area:<\/p>\n<pre>git reset README.md\r\ngit reset<\/pre>\n<p>Verify the updates on GitHub.<\/p>\n<p>To create a repository locally, first create a folder, change into it, then run:<\/p>\n<pre>git <strong>init<\/strong>\r\ngit <strong>remote add origin<\/strong> git@github.com:user\/private2.git\r\ngit <strong>remote -v<\/strong>\r\ngit <strong>push -u origin master<\/strong>\r\ngit push -u origin <strong>branchName<\/strong><\/pre>\n<p>Check which branch you are on:<\/p>\n<pre>git branch<\/pre>\n<p>List all branches, including remote ones:<\/p>\n<pre>git branch -a<\/pre>\n<p>Create a branch:<\/p>\n<pre>git branch firstBranch<\/pre>\n<p>Create a branch and switch to it:<\/p>\n<pre>git checkout -b firstBranch<\/pre>\n<p>To push the branch to remote for the first time:<\/p>\n<pre>git push --set-upstream origin firstBranch<\/pre>\n<p>Note: <strong>&#8211;set-upstream<\/strong> is the same as <strong>-u<\/strong> used previously.<\/p>\n<p>To delete a branch locally (safe way):<\/p>\n<pre>git branch -d firstBranch<\/pre>\n<p>Force delete a local branch, discarding all its changes:<\/p>\n<pre>git branch -D firstBranch<\/pre>\n<p>Delete the branch on the remote:<\/p>\n<pre>git push origin --delete firstBranch<\/pre>\n<p>Show the differences between the current branch and another:<\/p>\n<pre>git diff firstBranch<\/pre>\n<p>Merge the branch into master:<\/p>\n<pre>git merge firstBranch<\/pre>\n<p>Switch to another branch:<\/p>\n<pre>git checkout master<\/pre>\n<p>Rename or move files:<\/p>\n<pre>git mv fileName.txt fileNewName.txt\r\ngit mv dir1\/fileName dir2\/<\/pre>\n<p>List all commits:<\/p>\n<pre>git log\r\ngit log -p\r\ngit log --all --graph --oneline --decorate<\/pre>\n<p>View a specific commit:<\/p>\n<pre>git show b82ed4bb1a7dbe3ce291af17e73721dbe0c40011\r\ngit show b82ed4<\/pre>\n<p>Discard uncommitted changes to a file:<\/p>\n<pre>git checkout -- fileName<\/pre>\n<p>Revert the last commit (creates a new commit that undoes the changes):<\/p>\n<pre>git revert HEAD<\/pre>\n<p>Undo the last commit:<\/p>\n<pre>git reset HEAD<\/pre>\n<p>Revert a specific commit:<\/p>\n<pre>git reset 79645cdce5ef42595fee98306b9644c93f098e55<\/pre>\n<p>Or:<\/p>\n<pre>git reset --hard 79645cdce5ef42595fee98306b9644c93f098e55<\/pre>\n<p>Stash your changes to work on something else without committing:<\/p>\n<pre>git stash<\/pre>\n<p>List all stashed changes:<\/p>\n<pre>git stash list<\/pre>\n<p>Show what is in the stash:<\/p>\n<pre>git stash show<\/pre>\n<p>Restore stashed changes:<\/p>\n<pre>git stash apply<\/pre>\n<p>Search for a string across all commit history:<\/p>\n<pre>git log -S 'text' --source --all<\/pre>\n<p>Search using a regular expression:<\/p>\n<pre>git log -G \"regex expression\" --source --all<\/pre>\n<p>Squash all commits into one (use with caution):<\/p>\n<pre>git rebase --root -i<\/pre>\n<p>Remove a file from Git&#8217;s index. The <code>--cached<\/code> flag stops tracking the file without deleting it from your local filesystem:<\/p>\n<pre>git rm --cached .aws\/credentials<\/pre>\n<p>Set a custom timestamp for a commit:<\/p>\n<pre>GIT_AUTHOR_DATE=\"2024-01-15T10:30:01\" GIT_COMMITTER_DATE=\"2024-01-15T10:30:01\" git commit -m \"Initial commit.\"<\/pre>\n<hr \/>\n<p><strong>BONUS<\/strong><\/p>\n<p>Use Sandfly&#8217;s SSH Hunter to audit SSH keys. It is not open source, but this agentless tool can help you visualize what SSH keys exist in your system and how they are being used, including orphaned or unauthorized keys [<a href=\"https:\/\/sandflysecurity.com\/platform\/ssh-credential-security\/\">Link<\/a>].<\/p>\n<p>Create your own <strong>Private Git Server<\/strong> [<a href=\"https:\/\/dft.wiki\/?p=1728\">Link<\/a>].<\/p>\n","protected":false},"excerpt":{"rendered":"<p>First things first. Create an account and log in to GitHub [Link]. Go to Settings [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,6],"tags":[],"class_list":["post-1484","post","type-post","status-publish","format-standard","hentry","category-linux","category-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/1484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1484"}],"version-history":[{"count":30,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/1484\/revisions"}],"predecessor-version":[{"id":5760,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/1484\/revisions\/5760"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}