Automatically add remotes on git init

Is there a way to automatically set what your remotes are on a git repository after a git init?
I know I can have a git/config template, but I would need a way to reference the new repo name/directory to set the remote.

Example:

  • Rails which files to ignore for GIT
  • How to git pull rebase using GitPython library?
  • Can I make git merge --ff act like --ff-only?
  • Best workflow for developing npm packages that depend on each other
  • GIT - how to merge branches?
  • Git commit ERROR: Repository invalid
  • cd newProject
    git init
    

    and .git/config would already have:

    [remote "origin"]
        url = git@myserver:newProject
        fetch = +refs/heads/*:refs/remotes/origin/*
    

    at the end of the file.

    I suppose I could do this by creating a bash script to do the git init and then append to the config file, and run that file instead of using git init, but I was hoping there was a way I could do it as part of the git init command.

  • How so show SSH key in git log?
  • Rabbitvsc in Nautilus both git and svn
  • copy changed files from jenkins build
  • Setting up Android project to use git
  • bash: optimizing a git-aware shell prompt
  • Git(hub) forking own repo - pull requests
  • 2 Solutions collect form web for “Automatically add remotes on git init”

    You can create an alias in ~/.gitconfig. For example, to create a remote on example.com using the basename of the current directory as the project name:

    myinit = ! "git init; git remote add origin \"git@example.com:${PWD##*/}.git\""
    

    If you’re project is named “foo,” when you run git myinit in /path/to/foo it will initialize the the repository and set origin to “git@example.com:foo.git” for you.

    With a template as above,

    git init .
    sed -si s/newProject/itsrealname/ .git/config
    

    done. Why make a special command for trivial things like this, it’s easier to just do it than remember whatever name it gets.

    Git Baby is a git and github fan, let's start git clone.