Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Dakota Lewallen
Dakota Lewallen

Posted on • Edited on

     

Git Remotes in Five Minutes or Less

Recap

So far in this series we've covered the basics what a git repository is. As well as how to manage git repositories in your local environment. In this entry, we're going to look at how you can take your work, and make it available on the internet.

Vocabulary

  1. Remote
    • A non-local location for a repository. Accessed via URL. Stored as a key-value pair, where a given name is the key and the URL is the value.Note: A local repository may have many remotes.

Commands

user:~/project$git remote add <name> <URL>
Enter fullscreen modeExit fullscreen mode
  • When ran in an existing local repository, this command adds the URL to the list of remotes. Any branches from the remote repository, will follow a naming pattern of <name>/<branch>.
user:~/project$git clone <URL>
Enter fullscreen modeExit fullscreen mode
  • Creates a new repository containing the contents of the repository located at <URL>. Automatically adds the remote to the repositories list.
user:~/project$git fetchuser:~/project$git fetch <name>
Enter fullscreen modeExit fullscreen mode
  • Retrieves information about remote repositories. The name of a remote can be provided to retrieve its history alone.
user:~/project$git pulluser:~/project$git pull <name>user:~/project$git pull <name> <branch>
Enter fullscreen modeExit fullscreen mode
  • Retrieves information from remote repositories
  • Attempts to merge remote branch into local branch.
  • If no remote name is provided, the default is used.
  • If no branch name is provided, it will attempt to merge a remote branch with the same name as the locally active branch.
  • Similar togit merge from the last entry, you can pass flags to the command to prevent automatically merging.
user:~/project$git pushuser:~/project$git push <name>user:~/project$git push <name> <branch>user:~/project$git push <name> :user:~/project$git push <name> <branch>:<remote>
Enter fullscreen modeExit fullscreen mode
  1. Send local changes to remote repository.
    • If no remote is specified, will attempt to update the remote for the current branch. You can use the--all flag to push all branches.
  2. Send current branch to <name>.
  3. Push <branch> to <name>.
  4. Using a colon in place of a branch name, will push all branches that exist in both the local and remote repositories.
  5. You can push local branches to remote branches with different names, by specifying the two, separated by a colon. Effectively merging your local branch with the remote branch, in the remote repository.
user:~/project$git remote rename <name> <new>user:~/project$git remote remove <name>
Enter fullscreen modeExit fullscreen mode
  1. Will change the name that is associated with the remote.
  2. Will remove the remote from the list repositories list.

More Information

Remotes are arguably the most valuable feature of Git. They enable anyone to work on any number of projects at any given time or location. While the commands above will get you running with remotes. The real magic comes from the remote providers. They've made their hosting free and openly available to anyone with an internet connection. By doing so, they've fundamentally changed people's access to software and the information it provides. If you're not familiar already, I would strongly suggest you spend some time getting familiar with them and the people they work with.


Find me onTwitter |LinkedIn
Sponsor me onGithub
Like the article?Buy me a coffee!

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

AWS Community Builder 👷‍♂️ | 3x AWS Certified 📝 | Empowering Developers
  • Location
    Indiana, US
  • Education
    Self-taught
  • Work
    Principal Software Engineer @ QsrSoft
  • Joined

More fromDakota Lewallen

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp