Skip to content

jaydipjadeja/git-basics

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 

Repository files navigation

Git basic commands

Getting started 😃

Download git-bash by clicking here.

Setting up your git

You have to set username and email in git, because every commit use this information

git config --global user.name "Nishant Patel"
git config --global user.email mpatel@example.com

Setup your editor

If you don't want to use default editor and what to use atom for that, you can write following to set editor

git config --global core.editor atom

Initialize repository

git init

Check status

git status

Check commit detail logs

git log

Check commit logs in one line

git log --oneline

Check the difference after a file modification

git diff

Adding Multiple files to staging area

git add .

Unstage previously staged commits

git reset HEAD -- .

Perform a commit

git commit -m "commit_message"

Create a branch and make a switch to thet branch

git checkout -b new_branch_name

To get list of all available branch

git branch

Show branch structure

git log --graph --decorate --oneline --all 
OR
git log --graph --simplify-by-decoration --oneline --all

Create a remote repository

git remote add origin "https://github.com/nishantkp/git-basics"(your-remote-repository)
git remote add upstream "https://github.com/cvbutani/git-basics"(pull-remote-repository)

Remove a remote repository

git remote rm origin

Get the list of all remote repository

git remote -v or git remote

Send commits to remote repository

git push origin master
origin -> remote repository name
master -> local repository branch

Get commits from remote repository

git pull origin master or git fetch origin master
origin -> remote repository name
master -> local repository branch

Dont forget to merge after using git fetch

Merging specific commit from one branch to another

Secenario : You were working on a certain branch of a git repository, and you committed some changes to it. Then you realize, this particular commit should also go to another branch of the repository BUT you are not ready for a complete merge. Maybe this commit was meant for the other branch?

git cherry-pick <commit-hash>

Branch renaming

Rename current local branch

git branch -m new-name

Rename local branch from different branch

git branch -m old-branch new-branch

Delete branch

Delete local branch

git branch -d local-branch

Delete remote branch

git push origin --delete remote-branch

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published