git clone -b <mybranch> --single-branch <git://sub.domain.com/repo.git>
No, git push only pushes commits from current local branch to remote branch that you specified in command.
You can tell git to push all branches by setting the --all argument
See the command description
Git Branch: is a developement workflow in the repository.
Every Git repo has minimum one branch called Main ( Previously called master).
- create new branch. (the starting point of branch is HEAD)
git branch <branch-name>
- Create a new branch from history or old commit
git branch <branch-name> <commit-hash>
- create new branch and switch/checkout to it
git checkout -b <branch-name>
Note: Cann't delete current active branch.
- delete single branch (merged or empty)
git branch -d <branch-name>
- force deleting branch (not empty)
git branch -D <branch-name>
- delete locally and remotely branch
git push -d <remote-name> <branch-name>
git branch -d <branch-name>
- rename single branch
git branch -m <old-name> <new-name>
In this section we will list all command related to working with git remotes.
git fetch --all
This command will fetch all remote origins.
General Syntax
git push <remote-name> <branch-name>
Other Usages:
- pushing only current active branch changes
git push
- Pushing all Branches of single remote, We can use This Command.
git push <remote-name> *
The * is Glob Operator
pushing main branch of remote origin
git push origin main
General Syntax
git pull <remote-name> <branch-name>
The git only Pull Current Active Branch, So switch/checkout to desire branch and pull it.
These Examples Don't Works:
- Pull all Branches of Single Remote using asterisk (*)
git pull <remote-name> *
- Pull all Branches of All Remotes
git pull --all
- Pulling another branch that does not current Active branch. Like that current active branch is main and you try to pull dev branch.
git pull origin dev
reset current branch with specific commit
git reset [--hard | --mixed] {HEAD | HASH }
reset branch with its remote
git reset [--hard] <remote-name>/<brnach-name>
Git Branch Resetting.
Reset: changes the files in the staging index OR working directroy to the state they had when a specified commit was made.
-
Make my project look like it did back then.
-
Move HEAD Pointer to a specific commit
Types:
- Soft (only back HEAD Pointer to specific commit)
- Mixed (Changes the Staging Index Only)
- Hard (Change the Staging Index and Working Directroy)
- Move HEAD Pointer.
- Does not change staging index.
- Does not change Working Directroy.
git reset --soft <tree-ish>
عند الانتقال الى commit سابقة، يجعل التغيرات التي حصلت من قبل الcommits الاحقة في الـStaging Index (staging area)
الفائدة منه هو تجميع الـ Commits اللاحقة في Commit واحدة.
- Move HEAD Pointer.
- Changes Staging Index to match repository.
git reset <tree-ish>
git reset --mixed <tree-ish>
عند الانتقال الى commit سابقة، يجعل التغيرات التي حصلت من قبل الcommits الاحقة في الـ Working Directroy.
الفائدة منه هو اعادة تنظم الـ Commits
- Move HEAD Pointer.
- Changes Staging index to match repository.
- Changes Wroking directroy to match repository.
git reset --hard <tree-ish>
العودة الى Commit سابقة وجعل كل شيئ مطابق لها. التغيرات اللاحقة لها سوف تهمل بالكامل.
الفائدة منه هو عمل تراجع Undo للـ Commits.
-
Tags allow making points in history as Important.
-
named reference to a commit.
-
most often used to mark releases (v1.0, v2.0, ...)
-
Can mark key feature or changes (eccommerce, design, ...)
-
can mark points for team discussion (bug, Issue123,...)
- Lightweight Tags
- Annotated Tags (lightweight with a message)
git tag <tag-name> <commit-hash>
git tag -a <tag-name> -m "message" <commit-hash>
اذا كنت غير متاكد ماذا تستخدم، فاستخدم الـ Annotated. يسمح لك باضافة رسالة وصف.
list all tags
git tag { --list | -ls }
list annotation message
git list -l -n
Filtering tags use this command
git tag -l "<filter>"
Show the tags content OR show the differents
git show <tag-name>
git diff <tag-name1>..<tag-name2>
git tag { --delete | -d } <tag-name>
Can not reterive deleted tags.
افتراضيا الـ Tags محلية ولكن يمكن مشاركتها
- Like Branches, Tags are local unless shared to a remote.
- git push does not transfer tags.
- Tags Must be explicitly transferred.
- git fetch automatically retrieves shard tags.
share single tag
git push <origin-name> <tag-name>
share all tags
git push <remote-name> --tags
الامر git fetch سوف يعمل fetch لجميع الـ commits و الـ shared tags. لكن اذا كان الغرض من الامر هو فقط tags استخدم الامر git fetch --tags الذي بدوره يعمل fetch لل tags مع الـcommits الضرورية لعملهم. (وهذه الحالة نادرة الاستخدام)
طريقة حذف الـTags مشابهة لطريقة حذف الـBranches
git push <origin-name> :<tag-name>
git push { --delete | -d } <remote-name> <tag-name>
examples:
git push origin :V1.0
git push --delete origin V1.1
الـ Tags هو معرف الى commit معينة في تاريخ الـ Commits.
- Tags are not branches.
- Tags Can be checked out just like any commit.
افضل طريقة لعمل checkout للـTags هي: انشاء فرع جديد خاص به من خلال الامر
git checkout -b <branch-name> <tag-name>
الطريقة الاخرى:
git checkout <tag-name>
التي سوف تضع المستودع بحالة Detached HEAD
وهي حالة تحصل عند عمل checkout الى commit في الـ Local repository فتشبه عمل فرع مؤقت unnamed branch فعند اضافة commits جديدة لا تربط او تعود الى اي فرع. وغالبا ما تحذف بعدة اسبوعان تقريبا.
عند حصول هذه الحالة يمكن الحل بعدة طرق :
- عمل Tags الـcommits في الـ Detached HEAD حتى نستطيع العودة لها.
git tag temp
- انشاء فرع خاص لها
git branch temp_branch
- الطريقة الافضل هي:
git checkout -b temp_branch
- checking out a commit puts the local respository in "detached HEAD" state
- Like being on an unnamed branch.
- New Commits will not belong to any branch.
- detached commits will be garbage collected (~ 2 weeks)