You are here

Git Introduction Part One

Important Commands for git are as follows.

Install git on Ubuntu
sudo apt-get install git-core git-doc gitweb git-gui gitk git-email git-svn

Make any Folder version control repository with git

git init

Check the status
git status
Check the branch

git branch
to stage the changes
git add . or git add for adding only one file at a time

git reset HEAD . to unstage the changes git reset HEAD for unstaging only one file

Discard the changes made since last checkout
git checkout or git checkout .

looking at changes staged
git diff changes made but not staged
git diff --staged Staged changes
git diff --cached print staged changes

Ignore a file
echo filename > .gitignore { second step } git add .gitignore

Remove a file which is deleted from a file system
git rm

If your forgot to add something to .gitignore then use
git rm --cached can also use it as git rm log/\*.log or git rm \*.txt

git commit -m "message for commit"
git commit -a (commit with out the staging index)
git clone address

Create a branch and checkout at the same time
git checkout -b
git pull (for update local repository)
git diff (find out what has changed)
git push (to update main repository)

Git configurations & Change the color of text
git config --global user.name "D.K.Bhardwaj"
git config --global user.email "support@dkwebstudio.com"
git config --global color.branch auto
git config --global color.status auto
git config --global color.diff auto

Mislaneous git commands

git write-tree

Start a branch git branch {branch name}
List branches git branch or git show-branch
Change the working branch need to check our git checkout {branch name}
Create a new branch and check it out at the same time git checkout -b {branch name}
Add changed files git add .
remove the changes made lately in working dirctory go back to latest commit git reset --hard
git branch -d deletes a branch

See what has changed
git log --stat --summary

Ignore files
echo "file or directory name" > .gitignore

copy from production to dev local host
scp -rp .git user_name@ip_address:/var/www/folder/.git

git fetch
git pull

How merge work --- Check out the master then run this command
git merge

git stash (working directory changes are satashed on side)
checkout other branch
git stash apply

git checkout -b verse-9
git checkout -b verse-11

merge tool

help commands in three ways
$ git help
$ git --help
$ man git-

To see what has hapened in past
git log (It will show a very long history of what has commited in past )

git log -p -1 (It will show only last one change)

git log --stat (stats about the files )

git log --pritty=oneline (see one each commit in one line)

git log --since=2.weeks or 2.days
.

Add a change to a existing commit check it out add files or code then run this command
git commit --amend

See what remote serves are configured with this git repository
git remote -v will show more detail

Stop recoding changes to a file previously tracked
The reason for this is that once a file is tracked in the repository, it won't be ignored. That would have worked if we never wanted file_not_to_be_tracked_anymore file in the repository in the first place though.

The solution is to stop Git from tracking changes to the file:
git update-index --assume-unchanged file_not_to_be_tracked_anymore

Cleanup if a git process crash
git update-index --really-refresh
delete the file .git/index.lock

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer