DEV Community

stefaleon
stefaleon

Posted on • Edited on

Share Code With A Github Repository - A Quick Start Guide

 
Problem: You have code you want to share with others and you don’t know git…
 
Solution: Here are the basic steps to follow
 
1 Download and install Git

Git Page

Install Git on Win10 quick video

2 Navigate to the root folder of your project and create a file named .gitignore

Include inside it the folders and files that you do NOT want to share.

e.g.

node_modules
client/node_modules
config/default.json
private/my_secret_passwords.txt
Enter fullscreen mode Exit fullscreen mode

3 Initiate a git repository by typing

git init
Enter fullscreen mode Exit fullscreen mode

in the console

4 Stage all the files you are about to commit by typing

git add .
Enter fullscreen mode Exit fullscreen mode

5 Make the commit

git commit -m 'YOUR_DESCRIPTIVE_MESSAGE'
Enter fullscreen mode Exit fullscreen mode

YOUR_DESCRIPTIVE_MESSAGE is just informative text

 
So far you have commited your code to a local git repository.
 
Now you need to make it public, with a remote repository hosted in Github.
(There are alternatives to Github, such as Gitlab, Bitbucket and more but this is not the topic of this article…)

 

6 Sign up and sign in to Github: https://github.com/

7 From the top-right select the + sign , New Repository

8 Set a name for the new repository, e.g myrepo

9 In the next screen, copy the lines from the paragraph …or push an existing repository from the command line

image
e.g.

git remote add origin https://github.com/stefaleon/myrepo.git
git branch -M main
git push -u origin main
Enter fullscreen mode Exit fullscreen mode

10 Paste those lines in the console and enter

 

Now the contents of your project (except the .gitignore includes) are uploaded to a repository in Github which you can share via the url like
https://github.com/your_github_name/myrepo

 

thats all folks!

 
 

After on, if you update your code you can be updating your local commits with

git add .
git commit -m 'YOUR_NEW_COMMIT_MESSAGE"
Enter fullscreen mode Exit fullscreen mode

and also updating the remote copy of your repository in Github with

git push
Enter fullscreen mode Exit fullscreen mode

Top comments (0)