Table of Contents
- Create a new repository
- Remove the remote repository
- Add the new remote repository
- How to check URL for remote repository
- How to use token as credential for our repositories
- Wrapping up
Create a new repository
Belows are steps that we will create a new repository.
Create a new folder that contains our project
In this folder, typing git init command
# create an empty repository with .git folder to manage everything in this folder git init
Create our new things and push them to the local repository
git add . git commit -m "message"
If we don’t want to track some files, create .gitignore file.
Finally, we will connect the local repository with our Gitlab or Github
In the Gitlab or Github, create our new repository.
Then, in our working space, we will add the remote repository’s url in the loal configuration
git remote add origin <remote-repository-url> git push -u origin master
Remove the remote repository
# syntax git remote rm <repository-name> # for example git remote rm sample-repo
Add the new remote repository
git remote add <name_of_repository> url
url: means the path that points to repo, the tail of url is .git.
To check this remote whether it makes or not, use the syntax:
git remote git remote -v
When to use:
- when we want to merge a repository’s branches to the other repository’s branches.
How to check URL for remote repository
git config --get remote.origin.url
git remote show origin
To know more details a particular remote, use the generic command:
git remote show [remote-name] command
How to use token as credential for our repositories
Create a token on Github
Go to our account, then click to Setting menu item.
Scroll down and then select Developer settings item.
Then, we have:
Click on Personal access tokens item, we have:
Click Generate new token button, select our information for this token, especially about defining scopes of this personal tokens.
We can create this personal token looks like the image below.
Click Generate button, then we have:
We need to save this personal token to your secret place, and we will use it later.
Using that token for our local repository
# 1st step git remote set-url origin https://<personal-token>@<url-repository> # 2nd step git push
- Understanding what we will intend to do with Git.