Introduction
We have all heard of GitHub, right?
The beautiful UI, the development environment created by all those ongoing projects and their huge codebases, makes GitHub one of a kind platform for collaboration and to share your ideas with the world.
It has now become an essential part in a developer's life and especially in times like these where
'Work from Home' is now becoming the 'New Normal'.
But, sometimes these all can become a little overwhelming for young developers, who are just starting their journey and stepping into the world of Open Source Software Development.
One of the common areas, where beginners get stuck is uploading their written code files to GitHub!
Derived the logic, written some code, and the project is ready to be uploaded. But then the question arises
'How exactly am I supposed to push/upload these files to my repository?'🧐
I've got you covered there!
In this article we'll be covering the simple and step-by-step process of pushing your code files to your GitHub repository without any hassle.
Let's jump right into it!⚡️
The Way To Go
Alright, so for handling these processes and working with files, we use what is called as 'Git'.
It is version control system, which basically designed to handle everything from small to very large projects with speed and efficiency.
For pushing the files to GitHub, learning the Git commands and using the
terminal/command 👾 line for the task is a more efficient way rather than the traditional way of doing things using GUI.
Step-By-Step Guide
Follow this guide and tick the checkbox once you complete each step. At the end, you'll achieve what you were looking for!
Creating a new repository on GitHub
- [ ] To do that, click on the
+
sign besides the profile picture on the GitHub page
- [ ] Select 'new repository'
- [ ] Give your repository a name. For this example, lets go with "Practice"
- [ ] Click on 'create repository'
After this, a new page with some information would appear.
This we'll be using further ahead.
Navigating to your project folder and setting it as your current working directory
Using the command line, set your project folder as your current working directory as follow:
- [ ] use the
ls
command which lists down all the files and folder in the current directory. - [ ] Once you find your project folder, use the
cd
command to change the directory and set this as current working directory.
Now, the project folder has become current working directory and we can start using the Git commands.
Initialise the directory as a Git repository
Basically in this step, we are activating/creating a Git environment in our folder, in order to use the commands.
- [ ] using the command
git init
in the command line, the Git repository is initialised
Adding your files to the Git Repository
Now, the aim is to move all our files to this repository.
- [ ] use the command
git add .
, which will add all the files to the Git repo that we created - [ ] if you want to check whether the files have been added successfully, we use a command
git status
.
This will display all the added files in green colour if the process is carried out successfully.
Commit the files in the repository
Commit means to save the changes to the local repository.
This is an important process when it comes to saving your progress along the way, when using Git.
- [ ] run the command
git commit -m "-message-"
in order to save the changes that was done to the Git repository.
Adding the URL of your remote repository
By remote repository, means the repository that we have created on the GitHub account.
Here, the aim is to add the link for the GitHub repository where we have push our files to.
(the link is available on the repo page on GitHub)
- [ ] using the command
git remote add origin (URL)
, we are adding the remote repository with the given URL.
Pushing your code files
This the last step where we will be running a command to push all our files to the remote repository from the local Git repository.
- [ ] use the command
git push -u origin master
, this will push all your files from your local repository to the master branch of the GitHub repository created.
Conclusion
Yay! There you have all your precious code files in your GitHub, safe & sound.
Please share your valuable feedback on this article in the comment section below and can also suggest some changes for future topics as well!😇
Top comments (10)
Thanks for the article.
I feel like though this is the more advanced and detailed approach which would make you understand git console commands more fluently.
I think the easier approach is to initialise the repo on GitHub as an empty
Repo in the first place and then closing it on my local machine.
With that I don’t have to bother with all the remote configuration stuff because it’s already set up by the clone command.
thank you for sharing that info.
I'll definitely read about this approach and try to implement!
Thanks !
Thank you for reading !!
Very informative Article, Kunal!
Thank you so much !!
very informative!!thankyou
Thank you for the feedback 😃
Great post!
You should also check out this open source eBook on how to get started with Git:
bobbyiliev / introduction-to-git-and-github-ebook
Free Introduction to Git and GitHub eBook
This is an open-source introduction to Git and GitHub guide that will help you learn the basics of version control and start using Git for your SysOps, DevOps, and Dev projects. No matter if you are a DevOps/SysOps engineer, developer, or just a Linux enthusiast, you can use Git to track your code changes and collaborate with other members of your team or open source maintainers.
The guide is suitable for anyone working as a developer, system administrator, or a DevOps engineer and wants to learn the basics of Git, GitHub and version control in general.
To download a copy of the ebook use one of the following links:
Dark mode
Light mode
thank you for the resource! will definitely read that.....