DEV Community

stephen Githinji
stephen Githinji

Posted on

Pushing and Pulling Code From GitHub

Overview on GitHub

GitHub is among the most popular websites that provides teams the ability to carry out version control (VC). It is built on git, a popular decentralized version control system.

In software development, Git tracks changes made to the source code, hence enabling developers to collaborate and manage different versions of their product. GitHub provides an interface for hosting git repositories.

GitHUb Operations

Various operations in GitHub allow developers to host their git repositories and track their changes. The most common operations are commit, push, and pull.

Commit

Committing your code entails recording a snapshot of the changes to one or more files in your project.
First, one needs to add the file(s) they need to make changes to by invoking the command:

git add <file_name>
Enter fullscreen mode Exit fullscreen mode

This places them to the staging area.
To commit your changes use the command:

git commit -m "Message describing your changes."
Enter fullscreen mode Exit fullscreen mode

Push

The other operation is push. It used to upload your local repository content to a remote repository (such as GitHub).
To do so, use the command:

git push
Enter fullscreen mode Exit fullscreen mode

In case you have a branch, use the command:

git push <remote-name> <branch-name>
Enter fullscreen mode Exit fullscreen mode

prerequisites before pushing

  1. You must have a local Git repository with committed changes on your computer.
  2. A remote repository (like GitHub) linked to your local one. You can check your configured remote repos using the command:
 git remote -v
Enter fullscreen mode Exit fullscreen mode
  1. The necessary permissions to write to the remote repository.

Pull

Pulling is aimed at updating your current local working branch with the latest changes from a remote repository.
Use the command:

git pull
Enter fullscreen mode Exit fullscreen mode

In case your are pulling from a specific remote branch, use:

git pull <remote_name> <branch_name>
Enter fullscreen mode Exit fullscreen mode

Hint: Always ensure that you are always on the correct branch. You can use the command:

git checkout <branch_name>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)