![]() I find the "git diff" command most useful, when I've made minor changes, and/or want to inspect the actual text differences. So, to get from the current state of the remote to current state of your local copy, the files would have to be deleted. The reason the information is displayed this way is because Git considers your local repo to be the end result. This may seem confusing when you're first getting used to the "diff" command because we never had the files, so we definitely didn't delete them. When I do that we'll see a lot of red lines that have a "-" next to them indicating they've been deleted. I'll type "git diff origin/master" and press Enter to compare my repo with the master branch of the "origin" repo (which is the central remote in almost all cases.).If you'd like to see the actual changes in the files that will be merged, you can use the "git diff " command. Comparing our Repo with the Central Remote Repo with "git diff" We'll take a look at what to do in that scenario later. If you work on a team, or need to make a quick fix directly on your server for some reason, and forget to push it to the central repo, and pull it to your local repo before you do anymore work, you may run into an issue where your merge can not be fast-forwarded. If you work alone and always make your changes locally and push to live (never making a change directly on the live server) this should always be the case, and will make your work much easier. The "and can be fast-forwarded" part always makes me happy when I see it because it means I can merge the changes without having to worry about fixing merge conflicts. This shows us that our branch (on the live server) is behind 'origin/master' (the central repo) by 1 commit and that it can be fast-forwarded. ![]() Nothing to commit (working directory clean) # Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded. If we type "git status", we'll see the message: Now that they have the same information, if I type "git fetch" again, we won't see anything output to the screen because there's nothing new to show. When I pressed Enter, git compared my repo with the central repo, and since there was a difference, it downloaded the information about the difference. Type "git fetch" to query the central repo for any changes not present on the live server.Switch to the "Remote - Live" terminal tab.I'm calling the safe way because you can avoid code conflicts in real time by merging multiple edits in a single file instead of trying to overwrite one with the other. The first way I'll show you to move a change to the Live server will be the "safe" way. The "git merge" command is safer, but takes a little longer, while "git pull" is much faster, but has the potential to cause conflicts in the code. So, we now have the origin/master branch with us as remote branch and is not yet merged into the master branch of our local repository.Īfter reviewing the changes in the remote branch we can merge it into our local branch using the git merge command.There are two common ways to move the changes from the central repo to a remote repo, like the live server: "git merge" and "git pull". Now we want to fetch those changes from the master branch. Lets say other developers have committed changes and pushed those changes to the central repository which then got merged to the master branch. To view the remote branches that was fetched we use the git branch -r command.Īs the fetched commits are saved as remote branches and not integrated into our local branches it gives us an opportunity to review the changes and decide whether we want to merge the fetched changes in our local branches. If we want to fetch specific branch then we pass the branch name using the git fetch command. Note! origin is the name we set for the central repository in the previous tutorial Git Remote - Connecting with repository. Remote: Total 2 (delta 0), reused 0 (delta 0), pack-reused 0 Remote: Compressing objects: 100% (2/2), done. We use the git fetch command to fetch all the branches, commits and files of the remote connection. So, this helps in reviewing the commits before integrating them in the local working branches. The fetched commits are saved as remote branches separate from the local branches. When we use the git fetch commands we fetch the commits of a remote repository into our local repository. In this tutorial we will learn about Git fetch to import commits from remote repository.
0 Comments
Leave a Reply. |