![]() 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. git pull is a combination of git fetch and git merge.By Sam Corcos Here are all the Git commands I used last week, and what they do. git pull: Updates your current local working branch with all new commits from the corresponding remote branch on GitHub.git push: Uploads all local branch commits to the remote.git status: Always a good idea, this command shows you what branch you're on, what files are in the working or staging directory, and any other important information.git clone : Clone (download) a repository that already exists on GitHub, including all of the files, branches, and commits.These can be linked with branches on the remote, or they could exist with no remote counterpart. When you run git branch -all, you will also see the local working branches. This is safe to do if you are using GitHub, because branches merged via pull requests can be restored. To delete the remote tracking branches that are deleted on the remote, run git fetch -prune. But, these will stack up over time - they are not deleted automatically. These don't take up much room, so it's okay that Git does this by default. These update every time you run git fetch or git pull. These branches are read only copies of the branches on the remote. The branches that (by default) appear in red are the remote tracking branches. If you run git branch -all in your repository, you will notice a long list of branches. Git keeps track of the branches that you work on locally, as well as each of the branches in every remote associated with your local repo. ![]() The concept of branches can be confusing once it is combined with the concept of remotes. Unless you are using one of these four commands, all of your work is only happening locally. There are four commands within Git that prompt communication with the remote. ![]() It's typical to name this remote upstream. To make it easier to pull any changes to update the local copy of the fork from the original repository, many people add the original repository as a remote also. Then, the default remote would be origin, in reference to the fork. ![]() In this case, it's common to create and clone a fork. This can be common in open source, when a contributor needs to create a fork of a repository to have permission to push changes to the remote. You may need or want to work with multiple remotes for one local repository. It's like a key value pair, and origin is the default. origin is the human-friendly name for the URL that the remote repository is stored at. You may notice origin in many messages from Git. If you try running git remote -v in your repositories, you'll probably see something called origin.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |