GitHub is a code repository and hosting platform for version control and collaboration. GitHub is a Microsoft platform that help development team to collaborate on different projects from anywhere in the world. GitHub Desktop is an application that allows you to interact with GitHub using a Graphical User Interface (GUI) instead of using the command line. The
git push command is used to transfer or push your commit, this is usually made on your local branch in your computer to a remote repository like GitHub or any other code repository. If you need to read more on deployment of codes, code repository and API request you can read these: How to clone a repository and install software from GitHub on Windows, Azure DevOps and GitHub integration for Docker and Kubernetes deployment, How to deploy your Angular App to Azure from Visual Studio Code, How to Setup SonarLint in VS Code for your App Project, How to Use Postman with the Amazon Pinpoint API, How to use Postman for your POST Request.
Before you start this task you need to create a GitHub account here.
Using Command line to PUSH to GitHub
- First login to GitHub and create a new repository where you will push your code to in GitHub. Create a new repository by clicking the + sign and select New repository.
- Now fill up all the required details like the repository name, description which is optional and also make the repository public for this task.
- After creating your desired repository, you will need to open a Git Bash. If you do not have it installed yet you can download it here.
- Now move to the specific path in your local computer where you have your code saved locally by typing cd ‘path_name’. The cd commands stand for change directory which is used to change to the working directory on your system and locate your file.
Now initialize the git repository
- Use git init to initialize the repository. This command is used to create a new empty repository. The ‘.git‘ is created at the top level of your project and places all of the revision information in one place.
Now add the file to the new local repository.
- Use git add . in your Git bash to add all the files.
- Use git status in your Git bash to view all the files that will be part of the first commit.
You can Commit the files in your local repository by writing a commit message.
- You can create a commit message by writing git commit -m ‘your message’, this commands help to add the change to the local repository. The “m” is a flag for a message and help to define the changes that was carried out and the reason for the change.
- You can now copy your remote repository’s URL from your GitHub account.
- You will now need to add the URL copied from your remote repo to where your local content from your repository is pushed. Use this command git remote add origin ‘your_url_name’
- The “origin” is the remote name while the remote URL in this instance is https://github.com/mastert002/techdirectarchive_repo.git
Now push your code in your local repository to GitHub
- The command git push –u origin master is used for pushing your local code to GitHub.
- In the command the origin is the default remote repository while the –u is upstream and the master is the branch.
- Now fill in your GitHub username and password to complete the push to GitHub
If you supply the correct credentials you will get the below message
Your local repository will be pushed to GitHub Repository successfully
You can now view your files in your GitHub repository.
Using GitHub Desktop to PUSH your local code to GitHub repository.
You can download GitHub Desktop from here. This platform has a Graphical User Interface that can help you to push your code from local repository to a GitHub repository.
After installing the GitHub Desktop you can give it access to your GitHub account.
- Click on Authorize desktop
- Now create a new local repository inside
- Now click on Publish repository and enter the name of your repository and this will be automatically created on GitHub and all your codes inside the local repository will be pushed to the new repository on GitHub.
- When you check your GitHub repository you will see the new repository created.
Now move to GitHub Desktop and commit to master
- You can see the files that are added into the local repository. You also need to write your commit message and click “Commit to master or main”.
Pushing your main branch in GitHub Desktop to GitHub.
- You can click on “Push origin” to publish all your local codes to GitHub.
- Successfully pushed all codes to GitHub.
I hope you found this blog post on How to use Command-Line and GitHub Desktop to PUSH local code to GitHub interesting and helpful. In case you have any questions do not hesitate to ask in the comment section.