Git allows performing various operations on the Repositories including the local repositories and remote repositories. The user when downloads a project to work upon, a local repository is created to store a copy of the original project. This local repository stores the changes that are being made by the user. This way, the user can edit the changes before adding them to the main project. Multiple users can perform work on the same project at the same time by using local repositories.
Performing operations on these local repositories will not make any change to the original project. The changes will remain at the user’s end in the local repositories. This will reduce the creation of multiple copies on the central server. So, how will the changes get reflected in the main project? Git provides tools to interact with the central repository using your local repository. Git provides
git push command to make changes in the central repository. This command will add the most recent commits done on the local repository into the central repository. Similarly,
git pull and
git fetch commands are used to clone the most recent changes done on the central repository with the local repository.
Push Command: After the user is done with the modifications in the Local repository, there is a need to push these changes in the remote repository. This can be done with the git push command. Users can define which branch is to be pushed into the repository by passing its name as an argument.
By default, the data will be pushed from the current branch into the same branch of the remote repository.
Attributes of Push Command:
Pushing to the central repository can be done along with the use of certain attributes that can be used to perform multiple push operations on the repository. These attributes can be used to perform specific push on the repository. These are:
- --force: When the push command is unable to perform the task and the user has to either Rebase the branch or Merge the branches together. To overcome this problem there exists another git command called forcing the push.
$ git push <remote> --force
One must be very careful while using the –force command for pushing changes because to prevent the user from losing History, a non-fast-forward push method is rejected. The user will have to perform Merge operation on the branch and the later push the changes into the repository.
- --all: When there are multiple branches that are being used to perform work on the project by a specific user. The user can push whatever branch that is required, into the central repository according to their needs. If there’s a need to push these changes all at once, i.e. the user wants to push all the branches into the central repository together, then this command comes into use.
$ git push <remote> --all
- --tags: Tagging is the method of marking specific points in a git repository as being important. These tags are created by the user into the local repository and are needed to be pushed into the central repository for others to see. When the user pushes the changes to the central repository using the push command, these tags do not get pushed along. The user has to push these changes separately. This can be done by using the
$ git push <remote> --tags
This command will push all the tags at once. There’s a more preferred way to push tags, i.e. pushing tags one by one. This can be done by passing the tag name along with the push command.
$ git push <remote> <tag-name>
- --delete: Sometimes a user wants to delete a local or a remote branch from the current version of the project. This can be done by using the --delete command.
$ git push <remote> --delete <branch-name>
This command can also be used to delete a tag from the repository. This can be done by using the tag-name along with the delete command.
$ git push <remote> --delete <tag-name>