When working with other users' repositories, there are four basic commands you will need:
git pull and
git remote prune.
To grab a complete copy of another user's repository when you do not have a local copy of the repository already established, you will use:
git clone <URL>
You can choose from several different URLs when cloning a repository. When you view a repository while logged in to your account, you will be given the relevant URLs in the sidebar:
git clone <URL> will automatically create a new subfolder, fetch the contents of the repository into this subfolder, then create and checkout the default branch (usually "master"). If there are other branches on the remote you will need to create a local branch to work in, for example
git checkout -b fix_stuff origin/fix_stuff
If you already have a local repository with a remote set up for the desired project, you can grab all branches and tags for the existing remote using
git fetch <REMOTENAME>. By default,
git clone will create a remote named
origin pointing to the URL you cloned from. Fetch does not make any changes to local branches, so you will need to merge a remote branch with a paired local branch to incorporate newly fetch changes.
git fetch, you can use
git pull <REMOTENAME> <BRANCHNAME> to fetch a specific branch and merge it into your current local branch. For one-time pulls from other users' repositories, you can use a URL in place of a remote name.
pull potentially performs a merge on the retrieved changes, you should ensure that your working tree and index are clean before running the
pull command. If you run into a merge conflict you cannot resolve, or if you decide to abort the merge, you can use
git merge --abort to take the branch back to the state it was in before you pulled.
Sometimes branches are deleted from an upstream repository, perhaps even by the recommendation of the user interface after a merged pull request. By default,
git fetch will not remove any remote-tracking branches that have been deleted on the remote repository. Running
git fetch --prune or
git remote prune REMOTENAME will delete these tracking branches.