Push a Local Directory to a GitHub (Remote Directory)

github repository

In this post, you’ll learn how to push a directory on your local machine to a remote directory like GitHub using the Linux command line. A directory is pushed to the remote directory when you are done working on it locally.

Open your command line application, I’m using GitBash and navigate to your working directory

Let’s say i want to insert a text into a file called text.txt inside coursera-forking-lesson directory. type the following:

cat > text.txt
This is a new content

when when type the code cat > text.txt, enter the content of the text below it and press CTRL + D to save

Use git status to check the status of your working branch. You’ll be prompted that there are changes that are not staged for commit. Use git add filename to add the changed file for commit. in our case we will use git add text.txt to add the file to the commit stage.

Use git commit -m ‘ your commit comment ‘ to commit the added file, you’ll get a success message if the file was successfully commited.

Before you can use git push to push the file to the remote repository, you will have to create a repository on your GitHub with the exact directory name for instance ‘coursera-forking-lesson

Head to your GitHub account and create a repository. On your GitHub account, click on repository and click on ‘New’ at the top right. Put in your repository name (should be same with your local directory name), slect if repository should be private or public and click on ‘create repository’.

Back to your GitBash, use git push to push your directory to your remote server, if this is your first time you’ll be prompted to connect your GitBash to your GitHub account via the HTTPs.

You’re done! Congratulations

Leave a Reply

Your email address will not be published. Required fields are marked *