How to upload files in Github/ Gitlab with CLI

First, move to that directory from which you have to upload files.

example: I have to upload my upload.txt from Example/nipun folder at desktop so I will first go at path and directory.

Now I will execute commands.

$git init //for git initialize

$git add . //this will add our files in .git folder

$git commit -m “Nipun” // short message

In this short message is Add files via upload

$git remote add origin <Your repository URL>

$git push origin master

If you are facing error in upload files then execute this command

$git push -f origin master //-f for forcefully updating

👆 If you will do this then all the files will be deleted and then only single will upload

All the commands are the same for upload files in GitLab just change your URL example : 👇👇

at this:

$git remote add origin <Your repository URL> //gitlab / github URL

Let’s check :

All the commands that I have executed to upload a file on my GitHub repo
Successfully uploaded on my Github Repo.

🎊🎉We have successfully uploaded the file in GitHub 🎊🎉

If you have any query fill free to ask at



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store