How To Make A Git Repo Public
This tutorial provides an overview of how to prepare upwards a repository (repo) under Git version control. This resource will walk yous through initializing a Git repository for a new or existing project. Included below are workflow examples of repositories both created locally and cloned from remote repositories. This guide assumes a basic familiarity with a command-line interface.
The loftier level points this guide will encompass are:
- Initializing a new Git repo
- Cloning an existing Git repo
- Committing a modified version of a file to the repo
- Configuring a Git repo for remote collaboration
- Common Git version control commands
By the end of this module, you lot should exist able to create a Git repo, utilize common Git commands, commit a modified file, view your projection's history and configure a connectedness to a Git hosting service (Bitbucket).
What is a Git repository?
A Git repository is a virtual storage of your project. It allows you to relieve versions of your code, which you can access when needed.
Initializing a new repository: git init
To create a new repo, y'all'll utilise the git init
command. git init
is a one-fourth dimension command y'all use during the initial setup of a new repo. Executing this command will create a new .git
subdirectory in your current working directory. This will as well create a new master branch.
Versioning an existing projection with a new git repository
This example assumes you already accept an existing projection folder that you would like to create a repo within. Yous'll first cd
to the root project folder and then execute the git init
command.
cd /path/to/your/existing/code
git init
Pointing git init
to an existing project directory will execute the aforementioned initialization setup equally mentioned above, only scoped to that project directory.
git init <project directory>
Visit the git init page for a more detailed resources on git init
.
Cloning an existing repository: git clone
If a project has already been fix in a fundamental repository, the clone command is the about common way for users to obtain a local development clone. Similar git init
, cloning is more often than not a ane-fourth dimension operation. Once a developer has obtained a working copy, all version command operations are managed through their local repository.
git clone
is used to create a copy or clone of remote repositories. Yous laissez passer git clone
a repository URL. Git supports a few dissimilar network protocols and corresponding URL formats. In this example, we'll be using the Git SSH protocol. Git SSH URLs follow a template of: git@HOSTNAME:USERNAME/REPONAME.git
An case Git SSH URL would exist: git@bitbucket.org:rhyolight/javascript-data-store.git
where the template values friction match:
-
HOSTNAME: bitbucket.org
-
USERNAME: rhyolight
-
REPONAME: javascript-data-store
When executed, the latest version of the remote repo files on the chief branch will exist pulled down and added to a new binder. The new folder volition be named afterward the REPONAME in this instance javascript-data-store
. The folder volition incorporate the full history of the remote repository and a newly created primary branch.
For more documentation on git clone
usage and supported Git URL formats, visit the git clone Folio.
Saving changes to the repository: git add and git commit
Now that yous have a repository cloned or initialized, you tin can commit file version changes to it. The post-obit instance assumes yous take gear up up a project at /path/to/projection
. The steps being taken in this example are:
- Change directories to
/path/to/projection
- Create a new file
CommitTest.txt
with contents ~"test content for git tutorial"~ - git add
CommitTest.txt
to the repository staging area - Create a new commit with a bulletin describing what piece of work was washed in the commit
cd /path/to/projection
repeat "examination content for git tutorial" >> CommitTest.txt
git add CommitTest.txt
git commit -m "added CommitTest.txt to the repo"
After executing this example, your repo will now take CommitTest.txt
added to the history and volition track time to come updates to the file.
This example introduced ii additional git commands: add
and commit
. This was a very limited example, but both commands are covered more in depth on the git add and git commit pages. Another common utilize case for git add together
is the --all
selection. Executing git add --all
volition accept any changed and untracked files in the repo and add them to the repo and update the repo'southward working tree.
Repo-to-repo collaboration: git push
It's important to understand that Git's idea of a "working copy" is very different from the working copy you lot go past checking out source code from an SVN repository. Unlike SVN, Git makes no stardom betwixt the working copies and the central repository—they're all full-fledged Git repositories.
This makes collaborating with Git fundamentally dissimilar than with SVN. Whereas SVN depends on the relationship betwixt the central repository and the working copy, Git's collaboration model is based on repository-to-repository interaction. Instead of checking a working copy into SVN's central repository, y'all push or pull commits from one repository to another.
Of course, there's nil stopping y'all from giving certain Git repos special meaning. For example, by but designating 1 Git repo every bit the "fundamental" repository, it's possible to replicate a centralized workflow using Git. This is accomplished through conventions rather than being hardwired into the VCS itself.
Bare vs. cloned repositories
If y'all used git clone
in the previous "Initializing a new Repository" section to prepare up your local repository, your repository is already configured for remote collaboration. git clone
will automatically configure your repo with a remote pointed to the Git URL you cloned it from. This means that once y'all make changes to a file and commit them, yous can git push
those changes to the remote repository.
If you lot used git init
to make a fresh repo, you'll have no remote repo to push button changes to. A common design when initializing a new repo is to become to a hosted Git service like Bitbucket and create a repo there. The service volition provide a Git URL that yous can and then add to your local Git repository and git button
to the hosted repo. Once y'all have created a remote repo with your service of choice you will need to update your local repo with a mapping. Nosotros talk over this process in the Configuration & Fix guide beneath.
If you prefer to host your ain remote repo, you'll need to gear up a "Bare Repository." Both git init
and git clone
accept a --blank
statement. The most common apply case for blank repo is to create a remote central Git repository
Configuration & fix up: git config
Once y'all have a remote repo setup, you will need to add a remote repo url to your local git config
, and set up an upstream branch for your local branches. The git remote
command offers such utility.
git remote add <remote_name> <remote_repo_url>
This command will map remote repository at
to a ref in your local repo under
. One time you have mapped the remote repo you tin can push local branches to it.
git push button -u <remote_name> <local_branch_name>
This control will push the local repo branch under < local_branch_name >
to the remote repo at < remote_name >
.
For more in-depth await at git remote
, see the Git remote folio
.
In addition to configuring a remote repo URL, you may also need to set global Git configuration options such every bit username, or email. The git config
command lets you lot configure your Git installation (or an individual repository) from the command line. This command can define everything from user info, to preferences, to the behavior of a repository. Several common configuration options are listed below.
Git stores configuration options in 3 separate files, which lets you telescopic options to private repositories (local), user (Global), or the entire organization (organization):
- Local:
/.git/config - Global:
/.gitconfig
– User-specific settings. This is where options set with the --global flag are stored. - System:
$(prefix)/etc/gitconfig
– Arrangement-wide settings.
Define the author proper name to be used for all commits in the current repository. Typically, y'all'll want to apply the --global
flag to fix configuration options for the current user.
git config --global user.proper noun <name>
Define the author name to exist used for all commits past the current user.
Adding the --local
option or not passing a config level option at all, will gear up the user.proper name
for the electric current local repository.
git config --local user.email <e-mail>
Define the author email to be used for all commits by the current user.
git config --global allonym.<alias-name> <git-command>
Create a shortcut for a Git command. This is a powerful utility to create custom shortcuts for commonly used git commands. A simplistic example would be:
git config --global alias.ci commit
This creates a ci
control that yous tin can execute every bit a shortcut to git commit
. To learn more about git aliases visit the git config folio.
git config --system core.editor <editor>
Define the text editor used by commands similar git commit
for all users on the current automobile. The < editor >
statement should be the command that launches the desired editor (eastward.g., vi). This example introduces the --organization
option. The --organisation
choice will fix the configuration for the entire organisation, meaning all users and repos on a auto. For more detailed information on configuration levels visit the git config folio.
git config --global --edit
Open up the global configuration file in a text editor for transmission editing. An in-depth guide on how to configure a text editor for git to use tin can exist found on the Git config page.
Discussion
All configuration options are stored in plaintext files, so the git config
command is actually just a convenient command-line interface. Typically, you lot'll only need to configure a Git installation the first time you start working on a new evolution motorcar, and for virtually all cases, you lot'll want to use the --global
flag. One important exception is to override the author email address. You lot may wish to set your personal email accost for personal and open source repositories, and your professional email address for work-related repositories.
Git stores configuration options in iii dissever files, which lets you telescopic options to individual repositories, users, or the unabridged organization:
-
/.git/config -
~/.gitconfig
– User-specific settings. This is where options fix with the --global flag are stored. -
$(prefix)/etc/gitconfig
– System-wide settings.
When options in these files conflict, local settings override user settings, which override organisation-wide. If you open any of these files, you'll see something like the post-obit:
[user] proper name = John Smith email = john@instance.com [alias] st = status co = checkout br = branch up = rebase ci = commit [core] editor = vim
Yous can manually edit these values to the exact same effect as git config
.
Example
The first thing y'all'll want to do after installing Git is tell it your proper noun/e-mail and customize some of the default settings. A typical initial configuration might expect something similar the post-obit:
Tell Git who you are git config
git --global user.name "John Smith" git config --global user.e-mail john@example.com
Select your favorite text editor
git config --global cadre.editor vim
Add together some SVN-like aliases
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global allonym.upwards rebase
git config --global alias.ci commit
This will produce the ~ /.gitconfig
file from the previous department. Accept a more in-depth look at git config on the git config page.
Summary
Here nosotros demonstarted how to create a git repository using two methods: git init and git clone. This guide can exist applied to manage software source code or other content that needs to be versioned. Git add together, git commit, git push button, and git remote were besides introduced and utilized at a high level.
Read our guide about which code repository system is right for your team!
Source: https://www.atlassian.com/git/tutorials/setting-up-a-repository
0 Response to "How To Make A Git Repo Public"
Post a Comment