Useful GIT commands

Useful Git commands

Use caseCommandComment/Explanation
Download (clone) a remote GIT respositorygit clone [URL]This command does not clone sub-modules.

Example: git clone git@github.com:perthi/productivity.git
Download (clone) a remote GIT repository including all sub-modulesgit clone [URL] -b [branch] --recursiveClones everything including sub-modules.

Example: git clone git@github.com:perthi/logmaster.git -b master --recursive
Merge a feature branch into your development branch# git checkout develop
# git merge feature/myfeature
This assumes that you have renot branch called origin/feature/myfeature that is checked out locally
Check out an track a remote branchgit checkout --track origin/feature/myfeature
# This will checkout the remote feature branch *feature/myfeature* of the origin and track it. The name of the local branch will be *feature/myfeature*
Merge a feature branch into your development branch and squash all commits on the feature branch into a single commit on the development branch# git checkout develop
# git merge --squash feature/myfeature
Commit all changes and a add a commit message from the command linegit commit -a -m "commit message"
Push all local commits to the remote repository (origin)git push
Update your local repository with changes in the remote repositorygit pull
Failed merge: You have just done a merge that failed an regret it dearlygit reset --hard HEAD
This only works if the you have not yet pushed your changes to the remote
Remove branches that is still present in your local repo after they have been removed from the remote#git remote prune origin
#git branch -D mybranch ... X times

Delete a local branch # git branch -d
# git branch -D
The D (capital) option deletes the branch forcefully, i.e even if it is not fully merged.
Create a local branch and push it to a remote repository (origin), Set up the local branch to track the corresponding remote#git checkout -b feature/myfeature
#git push -u origin feature/myfeature
The first command creates and checks out a local branch called feature/myfeature. The second command creates a corresponding remote branch (origin/feature/myfeature) and tracks it
Delete a remote branchgit push origin --delete feature/myfeature
This will delete the branch origin/feature/myfeature at the remote
Create an annotated tag#git tag -a v1.4 -m "my version 1.4"
#git push --tags
List of useful git commands

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.