If you want to create a new branch, you can use git branch, with representing the name of the branch, such as “master”. The command git branch lists all branches on your local machine. If you don’t understand what branches are, there are other tutorials that are much more in-depth, and you should read those before proceeding ( here’s one). You’ll quickly find yourself using branches. So if you cloned a repo that belongs to someone else, you will not be able to push to GitHub until you change the origin using the commands above. Keep in mind that the remote repository will be linked to the account from which you cloned the repo. The most common way to copy a repo is to use git clone, followed by the URL of the repo. Follow the same process as git remote add origin, except use set-url instead to change the remote repo. Let’s say you copied a repo from someone else and want to change the remote repository from the original owner’s to your own GitHub account. The last one is used when you need to change the remote repository. From there, you can add, commit, and push to your remote repo. If you initialized your own Git repo and want to associate it with a GitHub repo, you’ll have to create one on GitHub, copy the URL provided, and use the command git remote add origin, with the URL provided by GitHub replacing “”. You can view that origin with the command git remote -v, which will list the URL of the remote repo. If you’ve copied a project from Github, it already has an origin. The default name (also known as an alias) for that remote repo is origin. If you’re using GitHub and you’re pushing code to a GitHub repo that’s stored online, you’re using a remote repo. If you don’t initialize Git, you cannot run any other Git commands within that repo. To initialize Git in a repository (repo), you just need to type the following command. I’ll start with the list of commonly used commands to make it easier for newbies to understand what is possible with Git, then move into the more advanced functionality and best practices. That’s all well and good when you’re working on a one-person team, a hackathon, or a throw-away app, but when stability and maintenance start to become a priority, cleaning up commits, sticking to a branching strategy, and writing coherent commit messages becomes important. But the average developer probably only uses these three commands 99% of the time: git add -all To keep things practical, I’m basing this list off of the actual Git commands I used over the past week.Īlmost every developer uses Git, and most likely GitHub. Well, here I am years later to compile such a list, and lay out some best practices that even intermediate-advanced developers should find useful. I remember thinking, “Wouldn’t it be nice if there were a list of the most common Git commands along with an explanation as to why they are useful?” Like most newbies, I started out searching StackOverflow for Git commands, then copy-pasting answers, without really understanding what they did. By Sam Corcos Here are all the Git commands I used last week, and what they do.
0 Comments
Leave a Reply. |