The Basic Commands Of Git YOU MUST KNOW!

image description

The Basic Commands Of Git YOU MUST KNOW!

To Start off,

you probably have basic setup of git in your local system, a repo and some knowledge of pushing the code but you might not know what commands perform what function?? So let's get started with a table:

S.No   Command Command Use
1. git add . Adds every file creation/updation/deletion to git tracking system.
2. git add <specific file/folder> Adds specific files or folders creation/updation/deletion to git tracking system.
3. git commit -m "your message" It sort of give a title to your changes that you made using git add for future recognization.
4. git push origin branch Pushes your commited changes in respective branch of your repo.
5. git pull origin branch Updates the code from your repo to your local system.
6. git rm Removes a file from git tracking.

 

After Basics,

No, The git doesn't stops here it has many and many commands that we might not use now but they can be life-saver at some point so we will discuss some of them...

Stashing

Sometimes, when you make changes in your project and pull the code from repo it may conflict if changes are in the same file.. It is the point where git still lacks but to solve it we use:

--include-untracked is a flag that we use to stash untracked files also.. (optional)

git stash --include-untracked

It basically saves your local not committed changes. To discard your changes from your local repo that are not being committed use:

Checkout

you can use this command to take your code to a specific commit or branch.

git checkout HEAD .

and as you have a backup in stash, you won't have any problem. If you want to get your code back use:

 How To Apply Stash?

Latest:

git stash apply

Specific:

git stash apply stash@{0} 

This would take your changes back to your project... Solve the conflicts that may occur.

 

Git, Why Conflicts??

If you have merge conflicts in your project, then you might be wondering how to solve them:

Why conflicts occurs?

It occurs when your local changes are those files that are also changed at repo so git don't know which file to accept so, when you pull, you might need to resolve conflicts on your own...

Then, how do I solve them?

Use a tool that clearly shows you what was your code and what is there's and allow you to accept code.. Like VS Code.

 

 

That's It For Today!

Related Posts

You may like these post too

image description

Deploying a Python Django Project on AWS: Step-by-Step Guide with Commands

Comments on this post

0 comments

Leave a comment

it’s easy to post a comment

image description
image description