![]() One way to find the SHA of a commit is to view the Git log. To checkout or switch to a specific commit, you can also use git checkout and pass the SHA of the commit instead of a branch name.Īfter all, branches are really just pointers and trackers of specific commits in the Git history. GIT SWITCH VS CHECKOUT HOW TO(my-feature)$ How to checkout a specific commit There is also a handy shortcut for returning to the previous branch you were on by passing - to git checkout instead of a branch name: (my-feature)$ git checkout. To switch to an existing branch, you can use git checkout again (without the -b flag) and pass the name of the branch you want to switch to: (my-feature)$ git checkout master How to switch to an existing branch in Git Here you can see a new branch created called my-feature which was branched off of master. The new branch's history will start at the current place of the branch you "branched off of."Īssuming you are currently on a branch called master: (master)$ git checkout -b my-feature This will create a new branch off of the current branch. ![]() To create a new branch in Git, you use the git checkout command and pass the -b flag with a name. To do this, you can use the git checkout command. On the other hand, the git checkout command has several uses, and we will utilize it daily.Switching branches is something you'll need to do often in Git. The git clone command will make a copy of a remote repository in our local machines, and we will most likely use it only once. In conclusion, the git checkout and git clone commands differ. This will discard the changes made to the file and revert it to its last committed state. We can see that Git has suggested using the git checkout command to discard the changes made to the run.py file. ![]() On running the git status command, we get: We will change the run.py file in our Sample-Repo. We can also use the git checkout command to cancel changes made to a file that is not yet committed. We will run the git checkout command, as illustrated below. How would we go about assuming we want to switch back to the master branch? The git checkout command comes in handy when we want to switch between branches in Git. Switch Between Branches With git checkout How do we go about it if we want to create a feature branch in our newly cloned Sample-Repo with the git checkout command? The git branch command only creates a new branch, while the git checkout command creates a new branch and switches to the newly created branch. However, we can also use the git checkout command to create a branch. We usually use the git branch command to create new branches. Create new branches Create a Branch With git checkout.Here are three common uses for the git checkout command. the git checkout CommandĪs opposed to the git clone command, the git checkout command has more than one use, and you will probably use it daily when working on a project. Let’s move on to the git checkout command. You will most likely use the git clone command once in a project. This will create a local copy of the remote repository on our machine. To clone the repository, open your terminal, navigate to the directory you wish to clone to and run the command, as illustrated below. In our case, we will use the HTTPS proxy. GIT SWITCH VS CHECKOUT CODETap the Code button and copy the URL depending on your authentication protocol.Open your GitHub web account and navigate to the repository you wish to clone.If you are unsure how to get the URL, follow the steps below. As we mentioned, the command requires the URL for the remote repository. We will utilize the git clone command in such a scenario. $ git clone Īssuming we have a remote Sample-Repo repository hosted on GitHub, how can we make a copy of the same on our local machine? Here is the common syntax for the command. It accepts a remote repository’s URL as a parameter. ![]() When invoked, it creates a copy of a remote repository in our local machine. The git clone command has only one function. We will start by defining each command and discussing the workflow. If you are coming from the SVN environment, you may find yourself confused as the equivalent of git clone in SVN is svn checkout.īy the end of this article, you will have all you need to navigate a Git repository with the git checkout and git clone commands. This article discusses the differences between the git checkout and the git clone commands in Git. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |