In this article, we will learn How to push local commits to the remote repository with git push command.
Total Views: 3226
In this article, we will learn How to push local commits to the remote repository with git push command. Git Push command is used to push the local repository changes to the remote repository.
In this article, we will learn:
1. How to push local repository changes to the remote repository?
2. How to push local repository changes to the remote repository forcefully?
3. How to delete a remote repository with Git push?
4. What is the use of dry run with Git push command?
5. How to push changes to remote server with verbose option?
1. How to push local repository changes to the remote repository?
For Demonstration, I already cloned a remote repository (GitHub). Use “git remote -v” command to check the list of remote configurations. As I cloned a repository, it comes with the remote named as “origin”.
Read: How to use Git Remote command in Git?
I added a index.html file in the working area and commit that file to the local repository.
Use “git status” command after committing the changes to the local repository. It clearly gives a message that “Your branch is ahead of ‘origin/main’ by 1 commit”.
Let’s push the changes of the main branch to the remote repository with “git push <Remote_Name> <Branch_Name>”.
You can view the changes on GitHub once all files pushed to the GitHub (remote repository) successfully.
2. How to push local repository changes to the remote repository forcefully?
Git force push command i.e., “git push <Remote_Name> <Branch_Name> -f” allows to push the changes to the repository without dealing with the conflicts. It will overwrite the changes on the remote repository so don’t use this command until you know what you are doing.
3. How to delete a remote repository with Git push?
To delete a branch from the remote repository, use “git push <Remote_Name> --delete <Branch_Name>”. For demonstration, I already have two branches, main and dev on the remote repository.
Let’s delete the remote repository with “git push origin --delete dev” command.
Once the branch deleted and pushed to the remote repository, refresh you page showing branches in the GitHub. You can see that “dev” branch is remoted from the GitHub.
4. What is the use of dry run with Git push command?
Dry run shows messages which only gives information regarding the changes going to happen on while using the git push command but actually it doesn’t push any changes to the remote server.
5. How to push changes to remote server with verbose option?
Use “git push <Remote_Name> <Branch_Name> -v” to push the changes with detailed explanation about the object while pushing the code to the remote repository. “-v” stands for the verbose.