Git How to Push Again a Failed Build
The basic command for pushing a local branch to a remote repository is git push.
This command has a variety of options and parameters you lot tin can pass to information technology, and in this article y'all'll larn the ones that you will apply the almost ofttimes.
How to push button a local Git co-operative to Origin
If yous run the unproblematic command git push, Git volition past default cull 2 more parameters for yous: the remote repository to push to and the branch to push button.
The general form of the command is this:
$ git push button <remote> <co-operative> By default, Git chooses origin for the remote and your electric current branch every bit the branch to push.
If your current branch is principal, the command git push will supply the 2 default parameters—effectively running git push origin main.
In the example below, the origin remote is a GitHub repository, and the electric current branch is principal:
(master)$ git remote -v origin git@github.com:johnmosesman/burner-repo.git (fetch) origin git@github.com:johnmosesman/burner-repo.git (push) (primary)$ git push button Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Delta compression using upwardly to 16 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 274 bytes | 274.00 KiB/due south, done. Total 3 (delta 0), reused 0 (delta 0) To github.com:johnmosesman/burner-repo.git b7f661f..ab77dd6 main -> main From the output you lot can see that the local principal branch was pushed to the remote main co-operative:
To github.com:johnmosesman/burner-repo.git b7f661f..ab77dd6 main -> main How to force push a co-operative in Git
Normally, you will push to a co-operative and add together to its commit history.
Just, there are times when you demand to forcefully overwrite the history of a branch.
In that location are a couple reasons you may desire to do this.
The get-go reason is to fix a mistake—although it is probably better to just brand a new commit reverting the changes.
The second and more common scenario is after an action like a rebase—which changes the commit history:
Internally, Git accomplishes [a rebase] by creating new commits and applying them to the specified base. It's very of import to empathize that even though the co-operative looks the same, information technology's composed of entirely new commits.
A rebase creates entirely new commits.
This means that if you try to push a branch that has been rebased locally—but non on the remote—the remote repository will recognize that the commit history has changed, and it will prevent you from pushing until you settle upwardly the differences:
(my-feature)$ git push To github.com:johnmosesman/burner-repo.git ! [rejected] my-feature -> my-feature (non-fast-forward) error: failed to push button some refs to 'git@github.com:johnmosesman/burner-repo.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote analogue. Integrate the remote changes (e.one thousand. hint: 'git pull ...') before pushing again. hint: Run across the 'Annotation most fast-frontward' in 'git push --help' for details. You could do a git pull here to merge the differences, but if you really want to overwrite the remote repository you lot can add the --force flag to your button:
(my-feature)$ git push button --forcefulness origin my-feature Enumerating objects: 1, done. Counting objects: 100% (1/one), done. Writing objects: 100% (1/1), 184 bytes | 184.00 KiB/s, washed. Total 1 (delta 0), reused 0 (delta 0) To github.com:johnmosesman/burner-repo.git + edb64e2...52f54da my-feature -> my-feature (forced update) (Annotation: you can use -f every bit a autograph instead of --force.)
A strength push is a destructive action—only utilize information technology when you're certain information technology'south what you want to do.
Force push button with lease
Sometimes y'all may want to force push button—but but if no one else has contributed to the branch.
If someone else contributes to your branch and pushes upward their changes to the remote—and yous strength push over it—you volition overwrite their changes.
To prevent this scenario, you lot can use the --force-with-lease option.
Again from the documentation:
--forcefulness-with-lease alone, without specifying the details, will protect all remote refs that are going to be updated by requiring their current value to be the same equally the remote-tracking co-operative nosotros have for them.
Basically, you're telling Git to forcefulness update this branch but if it looks the same every bit when you last saw it.
If you're collaborating with others on your branch, it would be expert to either avoid using --force or at least employ --force-with-lease to prevent losing changes other collaborators have made.
How to button to a branch of a dissimilar name on Git
You will commonly push your local branch to a remote co-operative of the same name—but not ever.
To push to a branch of a different proper name, yous just need to specify the branch yous want to push and the name of the branch you want to push to separated by a colon (:).
For example, if y'all want to push a branch called some-branch to my-feature:
(some-branch)$ git button origin some-branch:my-feature Full 0 (delta 0), reused 0 (delta 0) To github.com:johnmosesman/burner-repo.git + 728f0df...8bf04ea some-branch -> my-feature How to button all local branches to the remote
Yous won't need to push all branches from your local very often, but if you practice y'all can add the --all flag:
(primary)$ git branch * chief my-feature (main)$ git push button --all ... To github.com:johnmosesman/burner-repo.git b7f661f..6e36148 primary -> main * [new branch] my-feature -> my-characteristic Determination
The git push button command is one y'all'll be using frequently, and there are tons of options that tin be used with it. I encourage you to read the documentation for helpful options and shortcuts.
If you liked this tutorial, I likewise talk about topics like this on Twitter, and write about them on my site.
Learn to lawmaking for costless. freeCodeCamp'due south open up source curriculum has helped more than 40,000 people go jobs as developers. Get started
Source: https://www.freecodecamp.org/news/git-push-to-remote-branch-how-to-push-a-local-branch-to-origin/
0 Response to "Git How to Push Again a Failed Build"
Postar um comentário