Git /
Pushing and PullingGit pushPushing commits created locally to a remote repoThe simplest case where pushing becomes relevant is when working on a cloned repo. Pushing consists of updating the remote repository with new content that was developed locally. It is done with:
which can be conceived of as pushing the local content onto the remote repository. Note that you cannot push a branch to a remote repo if that branch is already checked out in the remote repo. The easiest way around this situation is to create and checkout another branch in the remote repo, even if it is a dummy branch. If your local branch is already configured to track a remote branch, the Pushing a branch created locally:If you created a new branch on your local repo and want it to be in the remote repo as well, you can do:
where -u is for Pushing forcefullySometimes, through using rebase or merging, your local repo will differ from your remote repo. One way to fix that is to painfully redo everything you have done locally on the remote repo (if you can even ssh there). The other way, if you are confident that your changes are good, is to squash the remote repo and force it to take your new version. This can be done using:
Git pullConversely, updating the local repo with newer information from the remote repo is called pulling, and can be conceived as pulling the remote content onto the local repo. It is done with:
If your local branch is already configured to track a remote branch, the Pulling nicelyWhen tracking a remote repo belonging to someone else, or where multiple people work, you might encounter occasions where your history and theirs differs. The nicest way to deal with this is by using rebase to first apply the changes that come from the remote branch. This can be done using the This is very useful when working in groups or even by yourself with multiple branches, to keep your working branch up to date with the latest releases and bugfixes so that, once you are done, your new feature can immediately be merged into the release branch. Pulling "forcefully"In a similar way as pushing an update forcefully, maybe you were working on something that did not pan out and want to go back to the remote's version of a branch. Unfortunately, the intuitive
|