Set a name that is identifiable for credit when review version history

git config --global “[firstname lastname]”

Set an email address that will be associated with each history marker

git config --global "[valid-email]"

Set automatic command line coloring for Git for easy reviewing

git config --global color.ui auto

SSL certificate problem

git config --global http.sslVerify false

Commit a file

git commit -m 'message'

Check status

git status

Check branch

git branch

Create new branch

git checkout -b <branchname>

Git add all files

git add -A

when you are confirming and want to merge to master

git merge <branchname>

You can tag the tip of the branch by archiving it, and then delete the branch.

git tag archive/<branchname> <branchname>
git branch -d <branchname>
git checkout master

The branch will be deleted, and can be retrieved later by checking out the tag, and recreating the branch.

git checkout archive/<branchname>
git checkout -b new_branch_name

Or more simply :

git checkout -b new_branch_name archive/<branchname>

Important Reset

git reset --hard origin/master
git pull origin master

NOTE: using git reset --hard will discard any uncommitted changes, and it can be easy to confuse yourself with this command if you're new to git, so make sure you have a sense of what it is going to do before proceeding.

git reset --hard <commit_before_merge>

You can find the <commit_before_merge> with git reflog, git log, or, if you're feeling the moxy (and haven't done anything else):

git reset --hard [email protected]{1}

Before push to master

First pull and merge conflict

git checkout <yourbranchname>
git pull origin master

When you have committed locally but not pushed, reset to last commit

The last commit will be removed from your Git history.

git reset --soft HEAD~1

If you are not familiar with this notation, “HEAD~1” means that you want to reset the HEAD (the last commit) to one commit before in the log history.

git log --oneline

3fad532  Last commit   (HEAD)
3bnaj03  Commit before HEAD   (HEAD~1)
vcn3ed5  Two commits before HEAD   (HEAD~2)

Made lots of changes but forgot to switch branch

Move To A New Branch

To move these changes to a new branch, run this command where “mybranch” is the name of the branch you want to create.

git checkout -b mybranch

Move To An Existing Branch

To move these changes to an exiting branch, just checkout the other branch with the regular checkout command. For example, run this command where “existingbranch” is the name of an existing branch.

git checkout existingbranch

Git stash save

This command is like Git stash. But this command comes with various options. I will discuss some important options in this post.

git stash save “Your stash message”.

Stashing untracked files

git stash save -u

git stash save --include-untracked
Git stash list

When you Git stash or Git stash save, Git will actually create a Git commit object with some name and then save it in your repo.

So it means that you can view the list of stashes you made at any time.

git stash list

This command takes the top most stash in the stack and applies it to the repo. In our case it is [email protected]{0}

Git stash apply

If you want to apply some other stash you can specify the stash id.

git stash apply [email protected]{1}

This command is very similar to stash apply but it deletes the stash from the stack after it is applied.

Git stash pop

Likewise, if you want a particular stash to pop you can specify the stash id.

git stash pop [email protected]{1}

Pull and Merge Single File

Go to your current directory

cd your_current_git_Directory

Set your username and repository of another repository/second(from want to copy)

git remote add -f repo-b [email protected]:<username>/<repository>.git
git remove add -f <repo/feature/premium> <clone add>

Now, Merge the filename you looking for(if you want file merge subfolder)

git checkout -p repo-b/master  <folder_name>/<filename>

Or merge filename only

git checkout -p repo-b/master  <filename>

And Remove repository

git remote rm repo-b

Git Rebase

git rebase -i HEAD~2

Save and exit


Quit without Saving


Force push and rewrite history!

git push --force origin master

Git Rebase From First Commit

git rebase -i --root
git rebase -i --root master