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
Apply a patch git apply –ignore-space-change –ignore-whitespace patch.diff

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

Adding a submodule:

git submodule add https://github.com/dmitriano/Awl.git lib/Awl
#Then after cloning:
git submodule init
git submodule update

Renaming the local and remote branch dev-data-race with android-1.0.15:

git branch -m dev-data-race android-1.0.15
git push origin :dev-data-race
git push --set-upstream origin android-1.0.15

Deleting remote branch dev-sanitizer:

git branch -d dev-sanitizer
git push origin --delete dev-sanitizer

Leave a Reply

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