DEV Community

kkipngenokoech
kkipngenokoech

Posted on

ADDING GIT REMOTE ORIGIN

Image description
Git is a source code management tool used in DevOps. It is a free and open-source version control system used to efficiently manage small to very large projects. Git is a version control system that allows multiple developers to collaborate on non-linear development by tracking changes in the source code.

step 1
Delete the .git directory present in your local environment

rm -rf .git
this removes specific files or a group of files from a Git repository. Git rm’s primary function is to remove tracked files from the Git index. Furthermore, git rm can be used to remove files from the staging index as well as the working directory.

so this means that there’s no longer a link between our local working directory and the remote repository

step 2
after removing the .git we are going to then initialize a new git repository by using the command

git init
this command creates a blank new repository

so we need to start tracking this files, we start creating versions of it and to do this we are going to use the git add -A command:

git add -A
the flag -A command means to track all files present.

after adding our files to our git repository we are going to commit them using the git commit command

git commit -m 'commit message'
when we try to push this code to the GitHub we are going to encounter an error

this is because we have not defined the connection between our local working repository and the remote repository in GitHub.

step 3
so here we are going to do just as you see in the recommendation you have been given by git, git really does a lot to ensure that we have a easy time interacting with it

git remote add takes two parameters, name and url.

name parameter means the name of the branch in which your code is going to reside in, most people prefer origin

the url is the http url found in your github repository

copy that code and run in your terminal

git remote add origin <paste your url here>
then push your code to your remote repository branch

git push origin
if you get an error saying “The current branch main has no upstream branch.” then you need to run this command

git push --set-upstream origin main
with that you have set a remote origin and have pushed your code to github!

Top comments (0)