We can add remote to repo we want to clone simple by using git remote add. To see more details of a repo we can give git remote -v as shown below and it will list all the remotes with their short names on which the programmer is working. I have cloned the repo from GitHub and kept in the test_git_tools directory which implicitly adds the repo called origin. In the below screenshot you can see these. If no name specified by default origin is the short name that’s given to the repo from which we might have cloned. This command lists them with their short names which admin or creator of repo might have mentioned while creating it. Git remote command can be used to get to know on which remote repo we are working. In this topic, we are going to learn about Git Origin Master. So when we collaborate with others on development we need to manage these repositories (also includes creating and removing repos) as well as pushing and pulling the data to them. These repos can be assigned read-write access categories depending on the type of users who are accessing them. Remote in contrast to the term suggests the availability of code on the server which can be local or connected by the internet. Basically, with git, you will be working on the remote repository which will be managed with versions by the git. If you follow the workflow covered in Part 3, you'll rarely need to use git pull -rebase.When you work on any project with Git then knowing about its remote is necessary. While -rebase is a helpful option for this scenario, it's best not make it a common practice. So, we should now be one commit ahead of origin/master and we can verify this by running git log. Similar to the output from git rebase, we see Git first brought our local master branch up-to-date, then re-applied our new commit. Let's try again using the -rebase option by running: git pull -rebase origin master So instead of running git merge it runs git rebase. What I want to do bring my branch up to date then add my new changes.Īs we learned in Part 3 this is exactly what git rebase does. And the local branch contains 1 commit as well as the remote branch contains 1 commit. We can verify this by running git status.Īlso, notice in output from git status that Git has detected that our branch has diverged from origin/master. Now I can run git merge -abort to abort the merge which reset the state of the repository back to before I ran git pull. This dumps me back to the command line without completing the merge. So, to prevent the merge, I'll clear the commit message and save. In this case, because I have new changes on an out of date branch. This means the commit history of the local and remote branches did not match. Git opens a text editor with a merge commit. Let's try running: git pull origin master This creates the scenario where I have local changes that have not been pushed to the remote and the remote has changes I have not pulled. However, this time, I'll make some changes and add a commit before running git pull. So, now that you know why you may receiving a merge conflict, let's talk about how to handle it.Īgain, I'll reset the master branch back a few commits. This way if running git pull doesn't behave as expected, for example by creating a merge commit, you'll know why. Nonetheless, it's important to understand the component steps. Since git pull is a shorthand it's therefore more common. We can prefix any branch with the remote name followed by / to reference its remote counterpart. Notice we passed origin/master to git merge. We can verify this by running git log -oneline -decorate -graph -all. We see from the output Git fast forwarded our branch with the recent changes. Which makes sense as we recently ran git fetch and nothing has changed. There's no output, so everything is up-to-date. Now instead of running git pull as we did in the init video, let's run git fetch. Let's demonstrate this by again resetting our master branch back a commits. In addition, I mentioned git pull is a shorthand for git fetch and git merge. In init: git pull, we used git pull to bring a branch up-to-date with its remote counterpart. In this video we'll break down git pull as well as learn how to use the -rebase option.
0 Comments
Leave a Reply. |