0% found this document useful (0 votes)
34 views4 pages

Git & Github

The document provides instructions for using common Git commands like configuring user information, initializing and cloning repositories, adding and committing files, viewing commit history, branching and merging, pushing and pulling from remote repositories, stashing and undoing changes.

Uploaded by

Tahreem Feroz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views4 pages

Git & Github

The document provides instructions for using common Git commands like configuring user information, initializing and cloning repositories, adding and committing files, viewing commit history, branching and merging, pushing and pulling from remote repositories, stashing and undoing changes.

Uploaded by

Tahreem Feroz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

GIT & GITHUB

 Download git in windows


 Use git bash for opening terminal
 git config --global user.name your name
 git config --global user.email your email
 git init : to initialize git
 ls --lart : shows folder and files where git repo is initialized
 git status: shows the file status
 git add file name: to take the file to staging area
 git commit :to add in git repo
 git commit opens vim editor, you can’t write in it, press ie to insert initial
commit and press esc key then press :WQ to exit the insert mode and show
what changes are made in file
 touch file name :creates blank files
 git add –A :to add multiple files in staging area
 git commit –m “your text here” : a shortcut method to commit files and
add message
 git checkout file name :brings back previous commit
 git checkout –f : brings back previous commit for all files
 git log : shows detail of user who commited the code
 git log –p -1 : no of commits you want to see (q to exit)
 git diff :compare working directory to staging area
 git diff --staged :compare staging area with last commit
 git rm --cached file name : to remove file from staging area but doesn’t
remove formhard disk
 git rm : removes file completely
 git status –s :short status
 touch .gitignore :don’t want to track those file, add file to ignore in this file

# Creating Repositories
git clone <repository_url> # Clone a remote repository to your local
machine

# Basic Operations
git commit -m "Commit message" # Commit staged changes with a
message
git commit -am "Commit message" # Add and commit changes in one
step (for tracked files)
git reset <file> # Unstage a file
git reset # Unstage all files
git log # View commit history
git show <commit_hash> # Show details of a specific commit

# Branches
git branch # List all branches (the asterisk marks the current
branch)
git branch <branch_name> # Create a new branch
git checkout <branch_name> # Switch to an existing branch
git checkout -b <new_branch_name> # Create and switch to a new branch
git merge <branch_name> # Merge a branch into the current branch
git branch -d <branch_name> # Delete a branch

# Remotes
git remote add origin <remote_url> # Add a remote repository
git push -u origin <branch_name> # Push the branch to the remote
repository
git pull origin <branch_name> # Pull changes from the remote repository
git clone <repository_url> # Clone a remote repository to your local
machine

# Stashing
git stash # Stash changes (save them for later)
git stash list # List all stashes
git stash apply # Apply the latest stash
git stash apply stash@{n} # Apply a specific stash (n is the stash index)

# Undoing Changes
git reset --hard HEAD # Discard all local changes (be careful!)
git checkout -- <file> # Discard changes in a specific file
git revert <commit_hash> # Create a new commit that undoes changes
from a specific commit

# Miscellaneous
git diff # Show changes between the working directory and
the staging area
git diff --cached # Show changes between the staging area and the
last commit
git clean -df # Remove untracked files and directories

You might also like