Difference between revisions of "HowTo - GIT & GitHub"

From Da Nerd Mage Wiki
Jump to navigation Jump to search
Tag: Reverted
Tag: Reverted
Line 15: Line 15:


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



Revision as of 18:33, 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
  • 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'''

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