Categorygit

Common git commands

Here is a list of commonly used git commands

  • Initiate a directory as git
git init --bare
  • Git clone
git clone url-to-git

example URL :user@domain.com:/home-path/username/directory/
  • Git status

it will show the files status – modified, tracking , untracked

git status
  • Git Add for tracking
git add filename
or 
git add .
dot is using to add all files

  • Git commit
git commit -m "commit message"

If the file is under git track we can combine both comments in one line like

git commit -am "your-message"
or
git  commit -a -m "your-message"

-a to add
-m to commit message
  • Push your changes to server
git push

or 
git push branch
  • Creating  branch in git
git branch  branch-name 
  • Switch to branch
git checkout branch-name
  • Create a new branch and switch to new branch
git checkout -b branch name
  • List all the branches
git branch -a
  • Merge Branch

Consider we have master branch A and another branch B,

To merge branch B changes to branch A,

git checkout branch A
git merge branch B

if any conflict happened, it will show conflict, we have to do modification and commit again.

  • Delete a branch
git branch -d <brach name>

this will delete if all the changes are merged, if you want to use force delete , even not merged,

git branch -D <branch name>
  • Upload branch into server at setting head for push
git push --set-upstream origin <branch name>
  • Stash all local changes
git stash
  • Take back stashed changes – This will take aback all the changes you stashed
git stash pop
  • Discard changes on one file
git checkout filename
  • Remove local commit  and reset to server head –  it will delete all the local changes
git reset --hard origin/branch name
  • List all the branches push/pull remote origin.

This will show all the remote and local branches and where it is pointing into

git remote show origin
  • Fetch and push origin list
git remote  -v
  • View uncommitted changes made
 git diff
  • To see all the logs
git log
  • To see log with difference
git log -p
  • Git log for a single file
git log -p file/path
-p will give changes also
  • Other options with git log
 git log --stat    //this will show only number of files changed and number of changes
git log --pretty=oneline    //show all the changes in one line with head and comment
git log --pretty=format:"%h - %an, %ar : %s"   //show with name time and commit message

git log --author=username  //show only one user commit

 


 

 

4,242 total views, no views today

Ignore files from git without .gitingore

We can remove tracking of git for some file using below comment .

git update-index --assume-unchanged <file full path>

To track the file again we can use below comment

git update-index --no-assume-unchanged <file  full path>

Now let us look How we can list all the files who is included in no-assume

We can type below comment in terminal

git ls-files -v

It will list like

H file 1
H file 2
h file 3
h file 4

Here we can see first character as capital or lower for some file.

If the first character is lowercase, it is marked as “assume unchanged”, else it is marked as “assume changed”

We can simply list all the “assume unchanged”files using below comment.

git ls-files -v | egrep -r "^h .*"

it will list only “assume unchanged” file list

Example

h file 3
h file 4

1,044 total views, 2 views today

Initiate git on server

How to initiate git through ssh

step 1 : login into ssh

step 2 : create a folder using mkdir commend and change to that folder

step 3 : write below comment to initate as a master branch

git init –bare

step 4 : change window.pack to 0

git config pack.window 0

step 5 : clone to local machine using

git clone username@host.com:/home/folder name(if needed)

step 5 : make changes

create a read me file and commit

git add .

git commit -am “intial commit ”

step 6 : push server

git push origin master

(before that make sure you take a pull from server git pull origin master)

 

step 7 :

To auto update in server

go to git_folder/hooks/post-update.sample and rename to post-update

and the past this code (change the folder name to targeted folder)

cd ~/public_html/folder|| exit
unset GIT_DIR
git pull origin master
exec git-update-server-info

 

enjoy coding

No views yet

© 2017 shabeeb Blog

Theme by Anders NorénUp ↑