Skip to content

Instantly share code, notes, and snippets.

@smahi
Last active November 18, 2019 14:41
Show Gist options
  • Save smahi/cf350a9b6c44082626fd83767e5ca16d to your computer and use it in GitHub Desktop.
Save smahi/cf350a9b6c44082626fd83767e5ca16d to your computer and use it in GitHub Desktop.

Git Resume

Configure Git (Git اعداد)

Locally (محليا)

git config user.name 'foo'

git config user.email '[email protected]'

Globally (على صعيد واسع)

git --global user.name 'foo'

Check Status (تحقق من حالة الملفات)

git status

Add file to stage (to be tracked) (تعقب الملفات)

git add .

Commit (tack a snapshot) (أحذ لقطة)

git commit -m'My commit'

History (log cmd) - السجل

git log

To show the last 2 commit - مشاهدة سجل لقطتين

git log -2

To show short version - مشاهدة سجل مختصر

git log --oneline

To show short version of 2 last commits - آخر لقطتين

git log --oneline -2

To show by date and time - مشاهدة السجل حسب الوقت

git log --before='2019-05-01T15:00:00'

git log --after='2019-05-01'

git log --since='2 days ago'

git log --after='2 days ago'

To show by author name - مشاهدة السجل حسب المؤلف

git log --author='smahi'

To get help on log command

git help log

To show files on specific commit - مشاهدة حالة الملفات للقطة معينة

git checkout 123fce

Other git commands - أوآمر أخرى

To rename a file/folder - اعادة تسمية ملفات

git mv foo.txt bar.txt

To remove a file/folder - حذف ملفات

git rm foo.txt

To show the modifications to be commit (staged) - مشاهدة التعديلات قبل أخذ لقطة

git diff --stage

To show the modifications that happens between last commit and a defined

git diff 123efe

To show the modification that happens between last commit and a defined one, including what happens in the specified one. (add ^ to the end of the hash number)

git diff 123efe^

To show the diff between the last commit and the the previous one

git diff HEAD^

To show diff between two commits (use two dots ..)

git diff 123456..345678

Undo things

To modify the commit message

git commit --amend

To Add a file to commit you just committed.

Add the new file, then

git add .

git commit --amend

To make changes on an already created file

Make to changes to the file, then

git add .

git commit --amend

Unstaging files

To unstage a file before committing (to untrack the file), then do

git reset HEAD foo.txt

To undo changes on a specific file

git checkout -- foo.txt

To undo changes on multiple files

git reset HEAD --hard

To undo a commit and go the previous one

git reset HEAD^ --hard

Remove untracked files/dirs

First do a simulation (dry-run) by passing -n

git clean -d -n

Then do the following to remove the files/dirs

git clean -d -f

Branching

You can have braches for ( development, stage, and production)

To create a new branch

git branch new_features

To work on the branch you need to switch to it.

git checkout new_features

Or combine the two command like so

git checkout -b new_feature

To merge the new_feature into master branch

git checkout master

git merge new_features

To delete the branch

git branch -d new_features

merge conflict

Modify the files that has conflicts then add them to stage, then commit

Rebasing

Is another technic of merging two branches, In it the history is kept lineare and more clean.

git checkout new_feature

git rebase master

git checkout master

git merge new_features

Interactive rebase

git rebase -i master

Then in the commit file you w'll see some help. then merge

git checkout master

git merge new_features

Using the head pointer for rabasing

Tilda ~ denote the previous n commit, in our example n = 3

git rebase -i HEAD~3

Tagging

Tags are versions off your app.

To create a tag

git tag v-1.2

To show the list of tags

git tag

To to go to a specific tag

git checkout v-1.2

Remote repository

Push code to remote repo

git push origin master

Fetch and Pull

To get latest changes we use fetch command

git fetch origin

git merge origin/master

Or do it in one command

git pull origin

Remote branches and tags

To create branches on remote server, using -u flag

git push -u origin new_features

To delete the remote branch

git push -u origin -d new_features

To fetch remotelly created branches

git fetch --all

To delete remote branches that have been deleted

git fetch --all --prune

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment