Monday 19 July 2021

Baisic Useful Git Commands

 

Pushing a fresh repository

Create a fresh repository(Any cloud repository).

Open terminal (for mac ) and command (windows) and type the below-mentioned command,

cd <location of your local code >
JavaScript

Initialize git using the below command,

git init
JavaScript

Add all the files to commit,

git add --all
JavaScript

To link your code to bitbucket use the below command,

git remote add origin <link to repo >
JavaScript

Commit the code mentioning the comment as below,

git commit -m "initial commit to push code to cloud"
JavaScript

Push the code to cloud,

git push -u origin Main
JavaScript

Where main is my repository branch

With this we have successfully pushed our code to the cloud, now we are going to discuss some of the scenarios where we get stuck and it is hard to find the solutions.

By mistake, I have committed the code but I don't want to push it.

Delete the commit keeping the work done,

git reset --soft HEAD~1
JavaScript

Clean the committed code or delete it,

git reset --hard HEAD~1
Commit all the edited files in 1 go
git commit -a -m ' comments'
-a = all edited files
-m = comment.
JavaScript

Push a particular file,

$ git status
$ git add <file_name>
$ git commit -m "<msg>"
$ git push origin <branch_name>
JavaScript

So in this article, we have gone through pushing up our local repository to the cloud and some of the commands which can help us in different scenarios and in the future articles I will be publishing more commands and the scenarios where we can use them

No comments:

Post a Comment

Baisic Useful Git Commands

  Pushing a fresh repository Create a fresh repository(Any cloud repository). Open terminal (for mac ) and command (windows) and type the be...