0% found this document useful (0 votes)
118 views

Git Commands

The document provides instructions for basic Git Bash commands. It begins by having the user configure their user name and email for commits. It then shows how to initialize a new local Git repository, add and commit files, and push changes to a remote repository on GitHub. The document also lists some intermediate commands for viewing changes, history, resets, and collaborating with remote repositories.

Uploaded by

Pinky Walia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views

Git Commands

The document provides instructions for basic Git Bash commands. It begins by having the user configure their user name and email for commits. It then shows how to initialize a new local Git repository, add and commit files, and push changes to a remote repository on GitHub. The document also lists some intermediate commands for viewing changes, history, resets, and collaborating with remote repositories.

Uploaded by

Pinky Walia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Basic Git Bash Commands 

 
#After everything is set, the first thing we have to do is to configure git 
with our name and email: 
git config --global user.name "<USER_NAME>" 
git config --global user.email "<USER_EMAIL>" 
Now to check your progress :- 
git config --list 
The following should be there: 
user.name=name 
[email protected] 
 
 
Now setting up your Git Repository 
cd desktop 
mkdir hello 
cd hello 
 
# Now we’re ready to initialize a brand new git repository. 
git init (​ ​git init ​command to initialize the repository:) 
 
# We can check for the current status of the git repository by using 
git status (​ ​Now use a ​git status​ command to show the status of the 
working tree:) 
 
# We can check if there is any file in the directory by 
- ls (if linux ​ls -a ) 
 
#to go to previous directory we use  
cd​ .. 
 
# Create and commit a new file 
touch hello.txt 
 
 
 
#To "register" the file for committing we need to add it to git using 
git add hello.txt 
 
# Checking for the status now indicates that the file is ready to be 
committed: 
git status 
 
# We can now commit it to the repository 
git commit -m "Add my first file" 
 
# Now open the file through git bash 
notepad hello.txt (​ for visual code ​code hello.txt ​) 
 

TO SEND / PUSH TO REPOSITORY ON GITHUB

git push origin master (​ if you are in master branch) 


 
git push -u origin YOUR_BRANCH_NAME​ ​( if you are in a different 
branch) 

Give your id and password :--

(reload your repo/ forked file)


Intermediate commands
Tracking----

#A patch-style view of the difference between the currently edited and


committed files
git diff

#The full list of changes since the beginning of time:


git log
git log --since=yesterday
git log --since=2weeks

#To discover why, when and by whom a certain line was added
git blame hello.txt

#To abort current uncommitted changes and restore the working copy to
the last committed state:
# Types of reset:
git reset --soft
git reset
git reset --hard
#To remove a file from staging area we use
git reset HEAD ~filename~

#To see the deleted files :


git reflog

#To view the statistics and facts about the last commit:
git show

#A remote called origin is automatically created if we cloned a remote


repository. The full address of that remote can be viewed with:
git remote -v

#to add origin and check whether remote is added or not


git remote add origin repo link
git remote

#To put changes from local repo in the remote repo


git push origin master

#From remote repo to get most recent changes.


git pull

common Git commands used in various situations:

start a working area (see also: git help tutorial)


clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing
one

work on the current change (see also: git help everyday)


add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status

grow, mark and tweak your common history


branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Forward-port local commits to the updated upstream head
tag Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)


fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local
branch
push Update remote refs along with associated objects

You might also like