Total Pageviews

4506

How To Create a Git Repository

To get started with git, you need to make sure you have it installed on your computer. You can download it from the official website and follow the instructions there to install it.

Create a new repository locally

To then create a new repository you need to first create a directory or folder for your project. In the command line with can be done using the mkdir command followed by the name of the folder you want to create:

$ mkdir

You can then navigate into that folder using the command line cd command. This allows you to change directories:

$ cd

Once you are in that directory a git repository can be initialised using the git init command. This will be:

$ git init

This will create a new repository based on the folder you are currently in. A .git folder should appear in the directory. Note: .git will initially be hidden; you can use the ls -a command to show all hidden files in a directory.

This will mean you have a git repository for your project and can start making branches and tracking changes on files you’ve added using git add and git commit.
Create a repository in an existing folder

If instead you already have folder that you have created you can navigate to that directory:

$ cd

Then use the git init command as before:

$ git init

If you then want to make sure that the repository is tracking your files you first need to use the git add command to add them to the repository. To add all the current files and folders you use:

$ git add .

After adding the files you then need to commit the changes to the repository. This is similar to taking a snapshot of your repository at a particular point in time. To commit changes use the command:

$ git commit -m “Initial commit”

For this, replace “initial commit” with a meaningful commit message that would describe the changes that you have made or the state of the current repository.

Connect to a remote repository

First you need to make a remote repository. To do this, we’ll use GitHub as an example, but other remote repository options like GitLab and BitBucket would work similarly. On GitHub, create a new empty repository. Give it a name and set whether you want to make it public or private. This should look something like this:

Create an empty GitHub repository

Log into your GitHub account and create a new repository by clicking the + icon in the upper-right corner of any page, then selecting New repository.


  • Name the repository “MyProject”
  • Add optional description
  • Ensure repository is set to “Public”
  • Click “Create repository”
Though not mandatory, choosing a license is an important part of openly sharing your creative work online. For help selecting an appropriate license see https://choosealicense.com/.

After creating the “hello-world” repository, GitHub will display the repository main web-page on your browser. This page contains information required to link your GitHub repository, remote, to the repository you created with Git on your own computer.

And the new repository should look something like this:



You can then link your local repository to the remote one using the command:

$ git remote add origin <remote_url>

Where the remote url is found on your remote repository. This will often take the form of git@github.com:<your_username>/<your_repo_name>.git. This will then connect your local repository to your remote one. You can verify that this connection has been made using the command:

$ git remote -v


Which should print the remote URL that was specified.

When pushing your work to the new remote repository you need to then set up where exactly you want to push to. This can be done using the command:

$ git remote --set-upstream origin main

This command creates a branch named main in our remote repository (if it doesn’t exist) and sets our local main branch to track and send changes to this remote branch. To then push your changes to the remote repository, you use the command:

$ git push origin main

In the case of an older repository, where the default primary branch may be named master instead of main, the command would be:

$ git push origin master

After providing your github username and password, you will receive following message:

remote: Support for password authentication was removed on August 13, 2021.

remote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.

fatal: Authentication failed for 'https://github.com/Tetraloops/MyProject.git/'
muhammadkhalil@192 django_project %

Then

Configure Access Token on GitHub

You can use token-based authentication in place of a password when performing Git operations. Github currently supports two types of personal access tokens: fine-grained personal access tokens and personal access tokens (classic). They recommend using fine-grained tokens whenever possible.

In the first step, we will create a personal Access Token on GitHub. Follow these steps to create one for your GitHub account:
  • Click on your GitHub profile icon on the top right corner and click on Settings
  • Choose Developer Settings on the menu on the left
  • Click fine-grained access tokens and Generate new token Add a specific note that will help you identify the scope of the access token
  • Choose the Expiration period from the drop down menu and select the scopes you want to grant the corresponding access to the generated access token. Make sure to select the minimum required scopes. For this workshop, public_repo should be enough.
  • Click on Generate Token

Now, a new page is opened in which you can see your personal access token and copy it.

Now, we need to run the following command to use this access token:

INPUT

$ git remote set-url origin https://<github-token>@github.com/<username>/<repository-name>.git

$ git push origin main

I had issues like this and there is no one specific set of instructions to resolve this. However I tried running this command and it worked for me

git config --global --unset http.proxy

Then run

git remote  set-url origin <repository link>

After committing your new changes, try running this command if regular push gives you an error:

git push origin <branch>  --force

fatal: the remote end hung up unexpectedly


Here is the answer

Here we go, I got my answer after trying too many ways in three days, for whoever will face this issue, do this stuff (read all below before starting):

  • At first, Open Git Bash
  • then, follow this instructions to generate SSH code and attach it to Github account.
  • Go to Github repository page
  • Click on Code button
  • Change it to SSH
  • Copy SSH CODE and use below, I determine your SSH code is git@github.com:user/user-repo.git
  • In your terminal write git remote add origin-ssh git@github.com:user/user-repo.git, SSH CODE is which you copied one step before
  • And finally push by git push -u origin-ssh
Congrats

No comments:

Post a Comment

ORA-00845: MEMORY_TARGET not supported on this system

 The shared memory file system should have enough space to accommodate the MEMORY_TARGET and MEMORY_MAX_TARGET values. To verify: SQL> sh...