Difference between revisions of "HowTo - GIT & GitHub"

From Da Nerd Mage Wiki
Jump to navigation Jump to search
(Created page with "<div>==GitHub==</div><div><br></div><div>* Required tools:</div><div>** <code>sudo apt install git</code></div><div>** [https://github.com/cli/cli/blob/trunk/docs/install_linux.md Installing gh on Linux and BSD]</div><div>***<code>curl -fsSL <nowiki>https://cli.github.com/packages/githubcli-archive-keyring.gpg</nowiki> {{!}} sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg</code></div><div>***<code>sudo chmod go+r /us...")
 
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
<div>==GitHub==</div><div><br></div><div>* Required tools:</div><div>** &lt;code&gt;sudo apt install git&lt;/code&gt;</div><div>** [https://github.com/cli/cli/blob/trunk/docs/install_linux.md Installing gh on Linux and BSD]</div><div>***&lt;code&gt;curl -fsSL &lt;nowiki&gt;https://cli.github.com/packages/githubcli-archive-keyring.gpg&lt;/nowiki&gt; {{!}} sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg&lt;/code&gt;</div><div>***&lt;code&gt;sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg&lt;/code&gt;</div><div>***&lt;code&gt;echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] &lt;nowiki&gt;https://cli.github.com/packages&lt;/nowiki&gt; stable main" {{!}} sudo tee /etc/apt/sources.list.d/github-cli.list &gt; /dev/null&lt;/code&gt;</div><div>***&lt;code&gt;sudo apt update&lt;/code&gt;</div><div>***&lt;code&gt;sudo apt install gh&lt;/code&gt;</div><div>* [https://docs.github.com/en/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax Basic writing and formatting syntax] (For your '''.md''' files)</div><div><br></div><div>===Creating a repository from scratch===</div><div>(Based on a local project folder)</div><div><br></div><div>&lt;syntaxhighlight lang="bash"&gt;</div><div>cd ~/Projects/Nuggit&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# Location of existing local folder</div><div>vi README.md .gitignore&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Create these useful files</div><div>git init&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#&nbsp;</div><div>git add README.md .gitignore&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#&nbsp;</div><div>git commit -m "first commit"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#&nbsp;</div><div>git branch -M main&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#&nbsp;</div><div>gh repo create Nuggit --source=. --private # Creating the actual Repo on GitHub</div><div>git push -u origin main&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Push the folder layout & initial files</div><div><br></div><div>git add *&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Add in the rest of the project</div><div>git commit -m "second commit"</div><div>git push -u origin main&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # & push it...</div><div>&lt;/syntaxhighlight&gt;</div><div><br></div><div>===Pulling down a repository for local work===</div><div>(Into a local project folder)</div><div><br></div><div>&lt;syntaxhighlight lang="bash"&gt;</div><div>cd ~/Projects&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# Location to create local folder</div><div>gh repo clone REPONAME</div><div>&lt;/syntaxhighlight&gt;</div><div><br></div><div>===Uploading Changes to a Repository===</div><div>(doesn't remove deleted files...)</div><div><br></div><div>&lt;syntaxhighlight lang="bash"&gt;</div><div>cd PROJECTFOLDER</div><div>git add *</div><div>git commit -m "MESSAGE"</div><div>git push&nbsp;</div><div>&lt;/syntaxhighlight&gt;</div><div><br></div><div>===Removing file(s) from a repository===</div><div><br></div><div>&lt;syntaxhighlight lang="bash"&gt;</div><div>cd PROJECTFOLDER</div><div>git rm FILESTOBEREMOVED</div><div>git commit -m "MESSAGE"</div><div>git push</div><div>&lt;/syntaxhighlight&gt;</div>
Despite being owned by Microsoft these days, GitHub is a rather handy tool. Working with it through the Web Interface will only get you so far tho... So, here're some tips on using it from the command line. (Based on running Linux. Mac should be about the same. Dunno about Windows.)
 
* Required tools:
** <code>sudo apt install git</code>
** [https://github.com/cli/cli/blob/trunk/docs/install_linux.md Installing gh on Linux and BSD]
***<code>curl -fsSL <nowiki>https://cli.github.com/packages/githubcli-archive-keyring.gpg</nowiki> {{!}} sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg</code>
***<code>sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg</code>
***<code>echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] <nowiki>https://cli.github.com/packages</nowiki> stable main" {{!}} sudo tee /etc/apt/sources.list.d/github-cli.list &gt; /dev/null</code>
***<code>sudo apt update</code>
***<code>sudo apt install gh</code>
**Then you'll need to set up gh with your account
***<code>gh auth login</code>
**** & follow the directions.
* [https://docs.github.com/en/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax Basic writing and formatting syntax] (For your '''.md''' files)
 
== Creating a repository from scratch ==
(Based on a local project folder)
 
<syntaxhighlight lang="bash">
cd PROJECTFOLDER                            # Location of existing local folder
vi README.md .gitignore                     # Create these useful files
git init                                     #  
git add README.md .gitignore                 #  
git commit -m "first commit"                 #  
git branch -M main                           #  
gh repo create REPONAME --source=. --private # Creating the actual Repo on GitHub
git push -u origin main                     # Push the folder layout & initial files
 
git add *                                   # Add in the rest of the project
git commit -m "second commit"
git push -u origin main                     # & push it...
</syntaxhighlight>
 
== Pulling down a repository for local work ==
(Into a local project folder)
 
<syntaxhighlight lang="bash">
cd ~/Projects                       # Location to create local folder
gh repo clone REPONAME
</syntaxhighlight>
 
=== Syncing a local copy from GitHub ===
 
<syntaxhighlight lang="bash">
cd PROJECTFOLDER
gh repo sync
</syntaxhighlight>
 
== Uploading Changes to a Repository ==
(doesn't remove deleted files...)
 
<syntaxhighlight lang="bash">
cd PROJECTFOLDER
git add *
git commit -m "MESSAGE"
git push  
</syntaxhighlight>
 
== Removing file(s) from a repository ==
 
<syntaxhighlight lang="bash">
cd PROJECTFOLDER
git rm FILESTOBEREMOVED
git commit -m "MESSAGE"
git push
</syntaxhighlight>

Latest revision as of 23:48, 23 September 2022

Despite being owned by Microsoft these days, GitHub is a rather handy tool. Working with it through the Web Interface will only get you so far tho... So, here're some tips on using it from the command line. (Based on running Linux. Mac should be about the same. Dunno about Windows.)

  • Required tools:
    • sudo apt install git
    • Installing gh on Linux and BSD
      • curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
      • sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
      • echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
      • sudo apt update
      • sudo apt install gh
    • Then you'll need to set up gh with your account
      • gh auth login
        • & follow the directions.
  • Basic writing and formatting syntax (For your .md files)

Creating a repository from scratch

(Based on a local project folder)

cd PROJECTFOLDER                             # Location of existing local folder
vi README.md .gitignore                      # Create these useful files
git init                                     # 
git add README.md .gitignore                 # 
git commit -m "first commit"                 # 
git branch -M main                           # 
gh repo create REPONAME --source=. --private # Creating the actual Repo on GitHub
git push -u origin main                      # Push the folder layout & initial files

git add *                                    # Add in the rest of the project
git commit -m "second commit"
git push -u origin main                      # & push it...

Pulling down a repository for local work

(Into a local project folder)

cd ~/Projects                       # Location to create local folder
gh repo clone REPONAME

Syncing a local copy from GitHub

cd PROJECTFOLDER
gh repo sync

Uploading Changes to a Repository

(doesn't remove deleted files...)

cd PROJECTFOLDER
git add *
git commit -m "MESSAGE"
git push

Removing file(s) from a repository

cd PROJECTFOLDER
git rm FILESTOBEREMOVED
git commit -m "MESSAGE"
git push