Version Control System (VSC)

How to use Command-Line on Git Bash and GitHub Desktop to PUSH local code to GitHub

mgithub

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.
image
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.
image-1
Create a new Repository
  • 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.
image-2
changing Directory

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.
image-3
Initializing the Repository

Now add the file to the new local repository.

  • Use git add . in your Git bash to add all the files.
image-4
Adding Files
  • Use git status in your Git bash to view all the files that will be part of the first commit.
image-5
Git Status

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.
image-6
First Commit
  • You can now copy your remote repository’s URL from your GitHub account.

image-7
GitHub Repository URL
  • 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
image-8
GitHub Access Authorization

If you supply the correct credentials you will get the below message

image-9
Authentication Succeeded

Your local repository will be pushed to GitHub Repository successfully

image-10
Files Pushed to GitHub Repo

You can now view your files in your GitHub repository.

image-11
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.

image-12
GitHub Desktop

After installing the GitHub Desktop you can give it access to your GitHub account.

image-13
Publish Repository
  • Click on Authorize desktop
image-14
Authorize GitHub Desktop
  • Now create a new local repository inside

C:\Users\techdirecharchives\Documents\GitHub

image-15
Creating a New Local Repository
  • 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.
image-16
Creating the Remote Directory from GitHub Desktop
  • When you check your GitHub repository you will see the new repository created.
image-17
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”.
image-18


Pushing your main branch in GitHub Desktop to GitHub.

  • You can click on “Push origin” to publish all your local codes to GitHub.
image-19
Files Pushed Remotely
  • Successfully pushed all codes to GitHub.
image-20
GitHub Repository

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.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x