Basic Git commands

Git installs as a normal package on Ubuntu:

sudo apt-get install git

Configuring Git user is an optional step:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

Type the following command to create an empty repository wherever your code is:

cd ~
git init

Now all the initialization is done.  Add something to the repository:

git add www
commit -m "first commit"

The basic Git commands are:

List files in the repository git ls-files
Undo local changes git checkout <filename>
List changed files those you need to commit git status <directory>
Commit changes git commit –m “message” <directory>
Show commit history for a branch git log -3 master..
Show files in a commit git diff-tree –no-commit-id –name-only -r <commit>
Disabling SSL cert check. git config —global http.sslVerify «false»
Delete the most recent commit, keeping the work you’ve done git reset –soft HEAD~1
Delete the most recent commit, destroying the work you’ve done git reset –hard HEAD~1
View the change history of a file gitk [filename] gitk –follow [filename]
Viewing Unpushed Git Commits git log origin/master..HEAD
List of files to be pushed git diff –stat –cached [remote/branch]
Show both local and remote branches git branch -a
Show remote branches git branch -r
Publish a local branch git push -u origin :
Show the remote address of a repo git remote -v

Probably one of the most interesting git commands is cherry-pick:

  1. What does cherry-picking a commit with git mean?

Git visual tools:

sudo apt-get install qgit
sudo apt-get install melt

Leave a Reply

Your email address will not be published. Required fields are marked *