0% found this document useful (0 votes)
24 views

Comandos Git

Uploaded by

Bryan Toapaxi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Comandos Git

Uploaded by

Bryan Toapaxi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Command

git init
git clone repo_url
git clone
ssh://[email protected]/[username]/[repository-
name].git
git status
git add [file-name]
git add -A
git commit -m "[commit message]"
git rm -r [file-name.txt]

git branch

git branch -a
git branch [branch name]
git branch -d [branch name]
git branch -D [branch name]
git push origin --delete [branch name]
git checkout -b [branch name]
git checkout -b [branch name] origin/[branch
name]

git branch -m [old branch name] [new branch name]

git checkout [branch name]


git checkout -
git checkout -- [file-name.txt]
git merge [branch name]
git merge [source branch] [target branch]
git stash
git stash clear
git push origin [branch name]

git push -u origin [branch name]

git push

git push origin --delete [branch name]


git pull
git pull origin [branch name]
git remote add origin
ssh://[email protected]/[username]/[repository-
name].git
git remote set-url origin
ssh://[email protected]/[username]/[repository-
name].git
git log
git log --summary
git log --oneline
git diff [source branch] [target branch]
git revert commitid
git config --global user.name "your_username"
git config --global user.email
"[email protected]"
git config --global --list
git config --global user.name "User Name"
git config --global user.email "email"
git config --global color.ui true

git init

git add <file>

git add README


git commit -m 'Initial project version'

git status

git add filename


git add -A
git add .
git add -p

git stash

git stash save "this is your custom message"


git stash apply
git stash apply stash@{stash_number}
git stash drop stash@{0}
git stash pop
git stash pop stash@{stash_number}
git stash list
git stash show
git diff stash@{0}

git commit -m 'commit message'

git commit filename -m 'commit message'


git commit -am 'insert commit message'
git commit --amend 'new commit message'
git rebase -i

git reset --soft HEAD~number_of_commits


git checkout -b branchname
git checkout -
git push -u origin branchname
git branch -d branchname

git branch -D branchname

git remote prune origin


git branch -a
git branch -a --merged

git branch -a --no-merged

git branch
git branch -r
git rebase origin/master

git push origin +branchname

git fetch origin

git checkout -b test origin/test

git branch -rd origin/branchname


git push origin --delete branchname
git push origin:branchname

git checkout trunk/master

git merge branchname


git merge --abort

git pull origin master

git branch --set-upstream-to=origin/foo foo

git reset --mixed [sha]

git reset HEAD origin/master -- filename


git reset HEAD -- filename
git reset HEAD^ -- filename
git reset --hard sha

git reset --hard

git remote show origin

git remote -v
git remote set-url origin
https://github.com/user/repo.git
git remote add [NAME]
https://github.com/user/fork-repo.git

git grep 'something'

git grep -n 'something'

git grep -C<number of lines> 'something'

git grep -B<number of lines> 'something'

git grep -A<number of lines> 'something'

git blame [filename]

git blame [filename] -l

git log

git log -p

git log -S 'something'

git log --author 'Author Name'

git log --oneline

git log --since=yesterday

git log --grep "term" --author "name"

git diff

git diff --cached

git diff --stat origin/master

git tag --contains [sha]

git shortlog -s --author 'Author Name'


git shortlog -s -n

git shortlog -n --author 'Author Name'

git shortlog -s -n

git checkout -- filename


git cat-file sha -p
git log --author="Author name" --pretty=tformat:
--numstat --since=month | awk '{ add += $1; subs
+= $2; loc += $1 - $2 } END { printf "added
lines: %s, removed lines: %s, total lines: %s\n",
add, subs, loc }'

lg = log --color --graph --pretty=format:'%Cred%h


%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)
%C(bold blue)<%an>%Creset' --abbrev-commit

git config --global alias.lg "log --graph --abbrev-commit --decorate


--format=format:'%C(bold blue)%h%C(reset) - %C(bold green)
(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an
%C(reset)%C(bold yellow)%d%C(reset)' --all"

git config --global alias.s "status --short"

git config --global alias.s "status -sb"


Description
Initialize a local Git repository
Clone public repository

Clone private repository

Check status
Add a file to the staging area
Add all new and changed files to the staging area
Commit changes
Remove a file (or folder)
List of branches (the asterisk denotes the current
branch)
List all branches (local and remote)
Create a new branch
Delete a branch
Delete a branch forcefully
Delete a remote branch
Create a new branch and switch to it
Clone a remote branch and switch to it

Rename a local branch


Switch to a branch
Switch to the branch last checked out
Discard changes to a file
Merge a branch into the active branch
Merge a branch into a target branch
Stash changes in a dirty working directory
Remove all stashed entries
Push a branch to your remote repository
Push changes to remote repository (and remember the
branch)
Push changes to remote repository (remembered
branch)
Delete a remote branch
Update local repository to the newest commit
Pull changes from remote repository

Add a remote repository

Set a repository's origin branch to SSH

View changes
View changes (detailed)
View changes (briefly)
Preview changes before merging
Revert commit changes
Set globally Username
Set globally Email id
Get global config

Applying colour to git


This creates a new subdirectory named .git that
contains all of your necessary repository files — a Git
repository skeleton. At this point, nothing in your project
is tracked yet.
To start version-controlling existing files you should
start by tracking those files and do an initial commit. To
accomplish that you should start with a few $ git add
that specifies the files you want to track followed by a
commit.

Checking the status of your files


The main tool you use to determine which files are in which state
is the $ git status command.
To stage changes for commit you need to add the file(s) - or in other words, stage file(s).Adding a file
Adding all files
Adding all files changes in a directory
Choosing what changes to add (this will got through all your changes and you can 'Y' or 'N' the changes)

Stashing files
Git stash is a very useful command, where git will 'hide' the
changes on a dirty directory - but no worries you can re-apply
them later. The command will save your local changes away and
revert the working directory to match the HEAD commit.Stash
local changes
Stash local changes with a custom message
Re-apply the changes you saved in your latest stash
Re-apply the changes you saved in a given stash number
Drops any stash by its number
Apply the stash and then immediately drop it from your stack
Release' a particular stash from your list of stashes
List all stashes
Show the latest stash changes
See diff details of a given stash number

Committing files
After adding/staging a file, the next step is to commit staged
file(s).Commit staged file(s)
Add file and commit
Add file and commit staged file
Amending a commit
Squashing commits together. This will give you an interface on
your core editor:
Commands:
p, pick = use commit
r, reword = use commit, but edit the commit message
e, edit = use commit, but stop for amending
s, squash = use commit, but meld into previous commit
f, fixup = like "squash", but discard this commit's log message
x, exec = run command (the rest of the line) using shell
Squashing commits together using reset --soft. ** WARNING: this will require force pushing commits, which is OK if this is
Branching and merging. Creating a local branch
Switching between 2 branches (in fact, this would work on terminal as well to switch between 2 directories - $ cd -)
Pushing local branch to remote
Deleting a local branch - this won't let you delete a branch that hasn't been merged yet
Deleting a local branch - this WILL delete a branch even if it hasn't
been merged yet!
Remove any remote refs you have locally that have been removed from your remote (you can substitute <origin> to any re
Viewing all branches, including local and remote branches
Viewing all branches that have been merged into your current branch, including local and remote
Viewing all branches that haven't been merged into your current
branch, including local and remote
Viewing local branches
Viewing remote branches
Rebase master branch into local branch

Pushing local branch after rebasing master into local branch


Fetching and checking out remote branches
This will fetch all the remote branches for you.

With the remote branches in hand, you now need to check out
the branch you are interested in, giving you a local working copy:

Deleting a remote branch


Deleting a remote branch
Merging branch to trunk/master
First checkout trunk/master
Now merge branch to trunk/master
To cancel a merge

Updating a local repository with changes from a Github repository


Tracking existing branch

Resetting
Mixes your head with a give sha
This lets you do things like split a commit
Upstream master
The version from the most recent commit
The version before the most recent commit
Move head to specific commit

Reset the staging area and the working directory to match the
most recent commit. In addition to unstaging changes, the --hard
flag tells Git to overwrite all changes in the working directory, too.

Git remote
Show where 'origin' is pointing to and also tracked branches
Show where 'origin' is pointing to

Change the 'origin' remote's URL


Add a new 'origin'
Usually use to 'rebase' from forks
Git grep
'Searches' for parts of strings in a directory
'Searches' for parts of strings in a directory and the -n prints out
the line numbers where git has found matches
'Searches' for parts of string in a context (some lines before and
some after the grepped term)
'Searches' for parts of string and also shows lines BEFORE the
grepped term
'Searches' for parts of string and also shows lines AFTER the
grepped term

Git blame
Show alteration history of a file with the name of the author
Show alteration history of a file with the name of the author &&
SHA

Show a list of all commits in a repository. This command shows


everything about a commit, such as commit ID, author, date and
commit message.
List of commits showing commit messages and changes

List of commits with the particular expression you are looking for
List of commits by author

Show a list of commits in a repository in a more summarised way.


This shows a shorter version of the commit ID and the commit
message.
Show a list of commits in a repository since yesterday
Shows log by author and searching for specific term inside the
commit message
Checking what you are committing
See all (non-staged) changes done to a local repo
See all (staged) changes done to a local repo
Check what the changes between the files you've committed and
the live repo
Useful commands
Check if a sha is in production
Number of commits by author
List of authors and commits to a repository sorted alphabetically.
Number of commits by contributors
List of commit comments by author. This also shows the total
number of commits by the author

List of authors and commits to a repository sorted alphabetically


Undo local changes to a File
Shows more detailed info about a commit

Show number of lines added and removed from a repository by


an author since some time in the past.

Shows the log in a more consisted way with the graph for
branching and merging

alias
- or in other words, stage file(s).Adding a file

your changes and you can 'Y' or 'N' the changes)


NING: this will require force pushing commits, which is OK if this is on a branch before you push to master or create a Pull Request.

on terminal as well to switch between 2 directories - $ cd -)

nch that hasn't been merged yet

n removed from your remote (you can substitute <origin> to any remote branch)

urrent branch, including local and remote


on a branch before you push to master or create a Pull Request.

mote branch)

You might also like