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

Tagging:

git tag -a v2.2.13 -m "Version 2.2.13 in Google Play."
git describe --tags
git tag
git show --summary v2.2.13
git push origin v2.2.13
git push origin --tags
git checkout v2.2.13
git checkout -b version2.2.13 v2.2.13
git log --pretty=oneline
git tag -a v2.2.13 9fceb02

Creating a repository on the server.

git init --bare tradebot.git

Pushing a newly created repository on the client.

git remote add origin https://git.developernote.com/tradebot.git
git push origin master

2 Responses to Basic Git commands

  1. dmitriano on November 8, 2018 at 1:18 PM:

    Truncating git history (https://passingcuriosity.com/2017/truncating-git-history/):
    git checkout –orphan temp e41d7f633c45c46bd42e97cecf93204191d9e4c9
    git commit -m “Truncate history”
    git rebase –onto temp e41d7f633c45c46bd42e97cecf93204191d9e4c9 master

  2. dmitriano on November 8, 2018 at 1:22 PM:

Leave a Reply

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