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 ""
git config --global "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 <branch-name>
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 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


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
git show refs/tags/v2.5.31#162:src/file.cpp
git tag -a v2.6.0 -m "Version 2.6.0 in Google Play, APK 181-184."
git push --delete origin v2.6.0
git tag --delete v2.6.0

Creating a repository on the server.

git init --bare tradebot.git

Pushing a newly created repository on the client.

git remote add origin
git push origin master

Checkout file from a different branch:

git ls-tree master src/LinesGame/LinesGameQt
git checkout master -- src/LinesGame/LinesGameQt/icons.qrc

Find and restore a deleted file or folder:

git rev-list -n 1 HEAD -- src/LinesGame/LinesGameQt/platform
git checkout 41264a71364dc8dbab96eec67e2b9d25332b2ca4^ -- src/LinesGame/LinesGameQt/platform

Save credentials:

git config --global credential.helper store

Looks like when I do

git config --global credential.useHttpPath true

in GitBash, Windows credential manager saves full repository URL, see Git credential helper – update password.

Fix your project to use a remote with credentials built in:

git remote set-url origin https://scuzzlebuzzle:<MYTOKEN>

3 Responses to Basic Git commands

  1. dmitriano says:

    Truncating git history (
    git checkout –orphan temp e41d7f633c45c46bd42e97cecf93204191d9e4c9
    git commit -m “Truncate history”
    git rebase –onto temp e41d7f633c45c46bd42e97cecf93204191d9e4c9 master

  2. superadmin says:

    clean all the modules recursively:
    git submodule foreach –recursive “git clean -dfx”

Leave a Reply

Your email address will not be published.