Git

Commanding Git

Pratik Kabade, 29 May 2022

Git is free and open source software for distributed version control: tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during software development.

Git Syntax

0. git config

Usage: git config –global user.name “[name]”

Usage: git config –global user.email “[email address]”

This command sets the author name and email address respectively to be used with your commits.

1. git init

Usage: git init [repository name]

This command is used to start a new repository.

2. git clone

Usage: git clone [url]

This command is used to obtain a repository from an existing URL.

3. git add

Usage: git add [file]

This command adds a file to the staging area.

Usage: git add *

This command adds one or more to the staging area.

4. git commit

Usage: git commit -m “[ Type in the commit message]”

This command records or snapshots the file permanently in the version history.

5. git diff

Usage: git diff

This command shows the file differences which are not yet staged.

Usage: git diff –staged

This command shows the differences between the files in the staging area and the latest version present.

Usage: git diff [first branch] [second branch]

This command shows the differences between the two branches mentioned.

6. git reset

Usage: git reset [file]

This command unstages the file, but it preserves the file contents.

Usage: git reset –hard [commit]

This command discards all history and goes back to the specified commit.

7. git status

Usage: git status

This command lists all the files that have to be committed.

8. git rm

Usage: git rm [file]

This command deletes the file from your working directory and stages the deletion.

9. git log

Usage: git log

This command is used to list the version history for the current branch.

Usage: git log –follow[file]

This command lists version history for a file, including the renaming of files also.

10. git show

Usage: git show [commit]

This command shows the metadata and content changes of the specified commit.

11. git tag

Usage: git tag [commitID]

This command is used to give tags to the specified commit.

12. git branch

Usage: git branch

This command lists all the local branches in the current repository.

Usage: git branch [branch name]

This command creates a new branch.

Git Commands

CREATE & PUSH

git init 
git add . 
git commit -m "initial commit" 
git commit --amend --date="Mon 27 Feb 14:00 2023 +0530" 
git branch -m main 
git remote add origin _ 
git push -u origin  

UPDATE LOCALLY

git fetch prune 
git pull -p 

BRANCH

git checkout -q main  
 
git branch -m my main  
git fetch origin  
git branch -u origin/main main  
git remote set-head origin -a  

NEW BLANK BRANCH

git checkout --orphan NEWBRANCH  
git rm -rf .