Skip to content

Instantly share code, notes, and snippets.

@morvanabonin
Last active December 15, 2021 14:05
Show Gist options
  • Save morvanabonin/4ada0307b4171b6415f2 to your computer and use it in GitHub Desktop.
Save morvanabonin/4ada0307b4171b6415f2 to your computer and use it in GitHub Desktop.
Git commands
$ git commit -a -m "Something message important here"
//To commit and add changed files.
$ git commit -am "Something message important here"
//To commit and add changed files.
$ git add
//To add new files (always when you will commit new files, you need to use git add not git -a -m/ -am)
$ git log
//To verify the history of changes recorded in repository.
$ git log -n 2
//This command shows the last two commits.
$ git log --oneline
//To show a summary of all commits on the project.
$ git log --stat
//To show a summary of all changes on the project, this command shows all lines that were add and removed.
$ git log -n 2 --oneline --stat
//This is an example of combined commands.
############## BRANCHES ##################
$ git brach
To list all branches in your repository, ordered by name
$ git branch <nome_branch>
//Create a new local branch
$ git push origin <nome_branch>:<nome_branch>
//Create a new remote branch
$ git branch -d <nome_branch>
//Delete a local branch
$ git push origin :<nome_branch>
//Delete a remote branch
$ git checkout -t origin/<nome_branch>
//This command pull the remote branch for local and checkout the branch you want to use
$ git branch | egrep "<condition in a regular expression>" | xargs git branch -d
//This command delete many local branches, using regular expression
git branch -vv | grep ': gone' | awk '{print $1}' | xargs git branch -d
// Other command to delete many local branches, if branch is not fully merged, using git branch -D
############## ADD ##################
git add -p, --patch file
// Interactively choose hunks of patch between the index and the work tree and add them to the index.
// This gives the user a chance to review the difference before adding modified contents to the index.
@morvanabonin
Copy link
Author

More commands, about git log.

@morvanabonin
Copy link
Author

Branch commands

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