Git Cheat Sheet 3
Git Cheat Sheet 3
Branch
$ git branch
# To see the list of branches and the current branch you're working on
See the remote branches
$ git branch -a
# You can see the remote branches too postfix -a
Create a Branch
$ git branch test_branch
# To create a new branch and stay in your current branch
To change the active branch
$ git checkout test_branch
#To change the active branch, we can run the checkout command
Create and checkout to a new branch in a single command
$ git checkout -b new_test_branch
# create and checkout to a new branch in a single command by postfixing -b to the checkout command:
To rename the current branch
$ git branch -m renamed_branch
# Run the command to rename the current branch to renamed_branch.
Delete a branch, run the following command:
$ git branch -D new_test_branch
# The -D option used above deletes a branch
- Retrieved from GitHowTo
The ultimate format of the log
Retrieved from https://githowto.com/history
$ git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
Let’s look at it in detail:
--pretty="..." defines the output format.
%h is the abbreviated hash of the commit
%d commit decorations (e.g. branch heads or tags)
%ad is the commit date
%s is the comment
%an is the name of the author
--graph tells git to display the commit tree in the form of an ASCII graph layout
--date=short keeps the date format short and nice