How to push code to GitHub

Today we will show you how to push code to GitHub. If you want to publish your work on github then you have to push your code on remote repository. In other words, push code to the github is used to keep the same work on remote and local repositories.

how to push code to github using cmd, how to publish your code on github, Adding an existing project to GitHub using the command line, Pushing commits to a remote repository, Step-By-Step Guide To Push Your First Project On GitHub, GitHub For Beginners: Commit, Push And Go, git commit and push, how to upload files to github from windows.

Way to push code to GitHub

  1. Create repository
  2. Check the status of working tree
  3. Add changes in local repository
  4. Commit the changes
  5. Push changes in remote repository

1. Create repository

Before we start, you have to create a repository / clone of your existing repository from GitHub. If you don’t know how to clone a repository in GitHub then please refer to the link below.

How to clone Git repository

2. Check the status of working tree

You have to execute the code below to check the status of the working tree.

Use the code below to discard all the changes in the working directory.

Use the code below to restore a specific file.

Note: Above command git restore will work before adding changes to the local repository for modified files. It won’t work for local untracked files.

3. Add changes in local repository

If you made any changes then first you have to add these changes in the local repository and stage them for the commit. Below command will help you to do it.

Use the code below to add an individual file.

Use the code below to add the whole folder.

Let’s say if you added the code by mistake then you can unstage it by the use of the code below.

Use the code below to unstage all files.

4. Commit the changes

Now it’s time to commit the changes and prepare it for the remote repository so we can push it.

If you want to remove the commit then use the code below.

If you want to remove the commit and discard the changes then use the code below.

5. Push changes in remote repository

At last, execute the command below to push the changes in remote repository.

Conclusion

Let’s combine all code together in one flow to push code in GitHub.

That’s it for today.
Thank you for reading. Happy Coding!

You may also like...

Leave a Reply

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