Create and add specific local folders to GitHub Repo

Create and add specific local folders to GitHub Repo

Working with .gitignore

ยท

2 min read

๐ŸŽฏ Target: create GitHub Repo for multi-collaboration working with code

๐Ÿ› ๏ธ Tools and prerequisites: Visual Studio Code (VSCode) and sign into GitHub profile

โ— Special Requirements: only 2 folders from the local folder needed to be add to GitHub Repo

Step 1 - Creating gitignore-file

As far as I need to add only 2 folders to GitHub Repo from more then 20 other local folders it's better to create gitignore-file and write there some conditions about it.

  1. Open root folder with folders you need for your repo in VSCode
  2. Create gitignore-file by input into Terminal:
touch .gitignore

So it will appear in root folder.

Step 2 - Edit gitignore-file

Open gitignore-file and add paths to your folders as shown on the picture below:

# Ignore everything:
*

# Except for:
!folder1/
!folder1/**

!folder2
!folder2/**

Save file.

Step 3 - Create GitHub Repo and push folders into it

  1. Click the Source Control icon in the Explorer sidebar or press Ctrl-Shift-G or click the Source control icon
  2. Click Publish to GitHub, enter repo name and choose if it'll be private or public repo

Once your data be published you will see notification in VSCode, so you can Open on GitHub button on the link and check it out.

6abdcbc23d.jpg

You're done! ๐Ÿ‘

Useful resources which I was using making this article:

stackoverflow.com - Using .gitignore to ignore everything but specific directories

ย