banner



How To Add Github Repository In Bash

This tutorial provides an overview of how to gear up upwards a repository (repo) under Git version control. This resource volition walk you lot through initializing a Git repository for a new or existing projection. 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.

video thumbnail

The high level points this guide will cover 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 terminate of this module, you should be able to create a Git repo, utilise mutual Git commands, commit a modified file, view your project'south history and configure a connection to a Git hosting service (Bitbucket).

What is a Git repository?

A Git repository is a virtual storage of your project. It allows y'all to save versions of your lawmaking, which you tin can access when needed.

Initializing a new repository: git init

To create a new repo, you'll use the git init command. git init is a i-fourth dimension command you apply during the initial setup of a new repo. Executing this control will create a new .git subdirectory in your electric current working directory. This will besides create a new main branch.

Versioning an existing project with a new git repository

This example assumes you already have an existing project binder that you would like to create a repo within. Y'all'll starting time cd to the root projection folder and then execute the git init command.

            cd /path/to/your/existing/lawmaking
git init

Pointing git init to an existing project directory volition execute the aforementioned initialization setup as mentioned above, just scoped to that project directory.

            git init <project directory>          

Visit the git init page for a more detailed resource on git init.

Cloning an existing repository: git clone

If a project has already been prepare up in a central repository, the clone command is the most mutual way for users to obtain a local development clone. Like git init, cloning is generally a one-time operation. One time a programmer has obtained a working copy, all version control operations are managed through their local repository.

git clone is used to create a re-create or clone of remote repositories. You pass git clone a repository URL. Git supports a few unlike network protocols and corresponding URL formats. In this case, 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 be: git@bitbucket.org:rhyolight/javascript-information-store.git where the template values match:

  • HOSTNAME: bitbucket.org
  • USERNAME: rhyolight
  • REPONAME: javascript-data-shop

When executed, the latest version of the remote repo files on the main branch volition be pulled down and added to a new folder. The new folder will exist named subsequently the REPONAME in this case javascript-data-shop. The folder will incorporate the full history of the remote repository and a newly created chief branch.

For more than documentation on git clone usage and supported Git URL formats, visit the git clone Page.

Saving changes to the repository: git add and git commit

Now that you lot have a repository cloned or initialized, you tin commit file version changes to information technology. The following example assumes you have gear up a project at /path/to/project. The steps being taken in this instance are:

  • Change directories to /path/to/project
  • 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 message describing what piece of work was done in the commit
            cd /path/to/project
echo "test content for git tutorial" >> CommitTest.txt
git add CommitTest.txt
git commit -m "added CommitTest.txt to the repo"

Afterward executing this example, your repo will now have CommitTest.txt added to the history and volition track future updates to the file.

This example introduced 2 additional git commands: add together and commit. This was a very limited instance, simply both commands are covered more in depth on the git add and git commit pages. Another mutual apply case for git add is the --all pick. Executing git add together --all will take whatsoever changed and untracked files in the repo and add them to the repo and update the repo's working tree.

Repo-to-repo collaboration: git push

It's important to understand that Git's thought of a "working copy" is very different from the working re-create you lot get by checking out source code from an SVN repository. Unlike SVN, Git makes no distinction between the working copies and the central repository—they're all full-fledged Git repositories.

This makes collaborating with Git fundamentally different than with SVN. Whereas SVN depends on the relationship between 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'south central repository, you push button or pull commits from ane repository to another.

Of class, there'southward zippo stopping y'all from giving certain Git repos special pregnant. For example, past simply designating 1 Git repo as the "key" repository, information technology'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 you used git clone in the previous "Initializing a new Repository" section to set 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 ways that once you lot make changes to a file and commit them, yous tin can git push those changes to the remote repository.

If you used git init to make a fresh repo, you'll take no remote repo to push changes to. A mutual design when initializing a new repo is to go to a hosted Git service similar Bitbucket and create a repo there. The service will provide a Git URL that you can and so add to your local Git repository and git push button to the hosted repo. In one case yous have created a remote repo with your service of choice you will demand to update your local repo with a mapping. Nosotros hash out this procedure in the Configuration & Set up guide below.

If you prefer to host your own remote repo, y'all'll demand to gear up a "Bare Repository." Both git init and git clone have a --blank argument. The most common apply case for bare repo is to create a remote central Git repository

Configuration & ready: git config

In one case you take a remote repo setup, you volition need to add a remote repo url to your local git config, and set an upstream co-operative for your local branches. The git remote control 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 . Once y'all have mapped the remote repo you lot can push local branches to it.

            git push -u <remote_name> <local_branch_name>          

This command will push the local repo branch under < local_branch_name > to the remote repo at < remote_name >.

For more in-depth look at git remote, encounter the Git remote folio.

In improver to configuring a remote repo URL, you may too demand to set global Git configuration options such equally username, or email. The git config command lets you lot configure your Git installation (or an individual repository) from the command line. This control 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 three separate files, which lets you scope options to individual repositories (local), user (Global), or the entire organisation (system):

  • Local: /.git/config – Repository-specific settings.
  • Global: /.gitconfig – User-specific settings. This is where options set up with the --global flag are stored.
  • System: $(prefix)/etc/gitconfig – System-broad settings.

Ascertain the author name to be used for all commits in the current repository. Typically, you'll want to use the --global flag to set configuration options for the current user.

            git config --global user.name <proper noun>          

Define the author name to be used for all commits past the current user.

Adding the --local option or not passing a config level option at all, volition gear up the user.name for the current local repository.

            git config --local user.email <electronic mail>          

Define the writer electronic mail to exist used for all commits by the current user.

            git config --global alias.<alias-name> <git-command>          

Create a shortcut for a Git control. This is a powerful utility to create custom shortcuts for commonly used git commands. A simplistic example would be:

            git config --global allonym.ci commit          

This creates a ci command that yous can execute as a shortcut to git commit. To learn more about git aliases visit the git config page.

            git config --system core.editor <editor>          

Define the text editor used past commands like git commit for all users on the current machine. The < editor > argument should be the command that launches the desired editor (e.thousand., vi). This example introduces the --system pick. The --organisation option will set the configuration for the entire system, significant all users and repos on a machine. For more detailed information on configuration levels visit the git config page.

            git config --global --edit          

Open the global configuration file in a text editor for manual editing. An in-depth guide on how to configure a text editor for git to apply tin can be constitute on the Git config page.

Discussion

All configuration options are stored in plaintext files, and then the git config command is actually just a convenient command-line interface. Typically, y'all'll just demand to configure a Git installation the start time you start working on a new development machine, and for virtually all cases, you'll want to utilize the --global flag. 1 important exception is to override the writer email address. You may wish to set your personal email address for personal and open source repositories, and your professional email address for work-related repositories.

Git stores configuration options in three separate files, which lets you scope options to private repositories, users, or the entire organisation:

  • /.git/config – Repository-specific settings.
  • ~/.gitconfig – User-specific settings. This is where options ready 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 arrangement-wide. If y'all open whatever of these files, you lot'll see something like the following:

            [user] name = John Smith email = john@instance.com [allonym] st = status co = checkout br = co-operative up = rebase ci = commit [core] editor = vim          

You can manually edit these values to the verbal same effect equally git config.

Instance

The first matter you lot'll want to practice after installing Git is tell it your proper noun/email and customize some of the default settings. A typical initial configuration might look something like the post-obit:

Tell Git who you lot are git config

            git --global user.name "John Smith" git config --global user.e-mail john@case.com          

Select your favorite text editor

            git config --global core.editor vim          

Add some SVN-like aliases

            git config --global allonym.st status
git config --global allonym.co checkout
git config --global allonym.br branch
git config --global alias.up rebase
git config --global alias.ci commit

This volition produce the ~ /.gitconfig file from the previous section. Accept a more than in-depth look at git config on the git config page.

Summary

Here we 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 exist versioned. Git add, git commit, git push, and git remote were also introduced and utilized at a high level.

Read our guide about which code repository system is right for your team!

How To Add Github Repository In Bash,

Source: https://www.atlassian.com/git/tutorials/setting-up-a-repository

Posted by: carterdianow.blogspot.com

0 Response to "How To Add Github Repository In Bash"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel