How to use GIT commands, list of GIT commands and it uses

GIT | Basic Username and Email Configuration
--------------------------------------------
# command for configuring user name
git config --global user.name "user name"

# command for configuring email address
git config --global user.email "email address"

GIT | Creating a repository
--------------------------------------------
# create a new local repo
git init "project"
#clone a remote repo
git clone "url"

GIT | Review History
--------------------------------------------
# list history of current branch
git log
# list history of a specific file
git log --follow "file-name"

GIT | Make Changes
--------------------------------------------
# check new or modified files to be committed
git status
# check the differences not yet staged
git diff
# add a file to stage
git add "file-name"
#check the difference between stage and last version of the file
git diff --staged
# unstage the file, preserve changes
git reset 
# add a file to repository
git commit -m “message”

GIT | branching
--------------------------------------------
# list of all branches
git branch
# command for creating a new branch
git branch "branch-name"
# switch to specified branch name
git checkout "branch-name"
# create a branch and switch to it
git checkout -b "branch-name"
(The above command is a shortcut for git branch and git checkout )

# merge specified branch history into current branch
git merge "branch-name"
# command for Deleting a branch
git branch -d "branch-name"

GIT | Revert commits
--------------------------------------------
# reverting all commits after your [commit], and preserving changes locally
git reset "commit-hash"
# Discards all history and changes back to the specified commit
git reset --hard "commit-hash"

GIT | Remotes
--------------------------------------------
# Adds a remote named "name" for the repository at
git remote add "name" 
# List remote
git remote
# list remote repository URL along with name
git remote -v
# Remove a remote named "name"
git remote remove "name"

GIT | Sync Changes
--------------------------------------------
# fetch all history from remote named
git fetch "upstream"
# merge branch “branch-name” from remote “updtream”
git merge "upstream" / "branch-name"
# pushing changes to branch “branch-name” of remote “upstream”
git push "upstream" "branch-name"

GIT | Save Fragments
--------------------------------------------
# temporarily store modified files
git stash
# restore the resently stashed files
git stash pop

GIT | Submitting Patches to Do
--------------------------------------------
# pull latest code changes to your working repository
git pull origin 8.0.x
# create a patch
git diff > [description]-[issue-number]-[comment-number].patch
# apply a patch
git apply -v [patchname.patch]
# revert the changes applied by the patch
git apply -R [patchname.patch]

Drush Commands
--------------------------------------------
# clear a specific cache, or all drupal caches
drush cc
# Rebuild a Drupal 8 site and clear all its caches
drush cache-rebuild
# enable a module
drush en "module-name"
# disable a module
drush dis "module-name"

Tags

Comments

> git init [repository name] // start a new repository.

> git clone [url] // git clone https://github.com/url/drupal

> git status

> git add
git add [file]
git add *

> git commit
git commit -m “[ Type in the commit message]” //records or snapshots the file permanently in the version history.
git commit -a //commits any files you’ve added with the git add command and also commits any files you’ve changed since then.

> git diff
git diff //shows the file differences which are not yet staged.
git diff [first branch] [second branch] // shows the differences between the two branches mentioned.

> git reset
git reset [file] //unstages the file, but it preserves the file contents.

> git tag
git tag [commitID] //used to give tags to the specified commit. //git tag 900e4b34e, git tag 8d6a003ff
git tag v1.0
git show
git show v1.0
git push origin v-1.0 //Sharing Tags
git push origin --tags // If you have a lot of tags that you want to push up at once
// Checking out Tags

> git branch
git branch //lists all the local branches in the current repository. //git branch phase1, git branch phase2
git branch [branch name] //creates a new branch.
git branch -d [branch name] //deletes the feature branch.

> git checkout
git checkout [branch name] //used to switch from one branch to another. //git checkout phase1, git checkout phase2
git checkout -b [branch name] // creates a new branch and also switches to it.

> git push branch phase1 // > git push origin phase1
** git push [variable name] :[branch name] //deletes a branch on your remote repository. //git push origin :phase1

> git merge
git merge [branch name] //merges the specified branch’s history into the current branch.

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
8 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.