TODO
$ git push -d <remote_name> <branch_name>
$ git branch -d <branch_name>
Note that in most cases the remote name is origin. In such a case you'll have to use the command like so.
$ git push -d origin <branch_name>
git init
git remote add origin <my-github-rep.git>
git fetch
git branch --set-upstream-to=origin/master
$ git remote
iqandreas
octopress
origin
$ git log --oneline
Flag that can be used to display the files that have been changed in the commit, as well as the number of lines that have been added or deleted.
$ git log --stat
This flag can be used to display the actual changes made to a file.
$ git log -p
$ git remote add origin [email protected]:AugustoCalado/Test-Repo.git
$ git push -u origin master
$ git branch branch_name -u your_new_remote/branch_name
$ git pull origin master --allow-unrelated-histories
$ git merge origin origin/master
... add and commit here...
$ git push origin master
Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory.
This command will then show a dialog like the following, for every hunk in your possible commit
Stash this hunk [y,n,q,a,d,e,?]?
y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk nor any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk nor any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
A hunk is a coherent diff of lines as git-diff produces it. To select a single file you'll have to decline adding hunks as long as you reach that file, then you might add all hunks from that file.
Observation Using the --patch-option is possible on different git commands (f.e. stash, commit and add).
$ git stash push -m stash_name example/file/path/and/file.html
Creates and checks out a new branch named starting from the commit at which the was originally created, applies the changes recorded in to the new working tree. It then drops the stash.
$ git stash show -p stash@{x}
$ git stash list --name-status
$ git stash push -m welcome_cart app/views/cart/filename.ext
$ git remote add github-repo <github-repo-url>
$ git checkout master
$ git push github-repo master # push current-repo master branch changes to github-repo master branch
$ git remote #shows the remotes tracked
- Rename Local Branch
$ git branch -m new-name
- If i am on a different branch
$ git branch -m old-name new-name
- Delete the old-name remote branch and PUSH the new-name local branch
$ git push origin :old-name new-name
- Reset upstream branch for the new
$ git push origin -u ne-name
$ git branch branchname <sha1-of-commit>
using a symbolic reference:
$ git branch branchname HEAD~3
To checkout the branch when creating it, use:
$ git checkout -b branchname <sha1-of-commit or HEAD~3>
$ git remote get-url origin
$ git remote -v
$ git remote show origin
- remove HTTP remote (for example with origin):
git remote remove origin
- add the SSH remote
git remote add origin [email protected]:path/to/project.git
- set the branch's remote again with
git push -u origin master
or
git branch --set-upstream-to=origin master
-
Commit all changes
-
Remove everything from the repository
$ git rm -r --cached .
-
rm is the remove command
-
-r
will allow recursive removal -
–cached
will only remove files from the index.
- Re add everything
$ git add .
- Commit
git commit -m ".gitignore fix"
Rebase to the commit immediately prior to the commit with the wrong date
$ git rebase <commit hash> -i
Result:
pick af09d0a Log and add new dependency # Commit with wrong date
pick 4e37143 exchanging stop by timeout for buffersize
pick 21fc337 Added simple styles in home.html
pick 8dc79f6 create readme
Replace pick with e (edit) on the line with that commit (the first one)
e af09d0a Log and add new dependency # Commit with wrong date
pick 4e37143 exchanging stop by timeout for buffersize
pick 21fc337 Added simple styles in home.html
pick 8dc79f6 create readme
Adjust the commit date with
$ git commit --amend --no-edit --date "6 Apr 2018"
to change the commit date instead of the author date:
GIT_COMMITTER_DATE="Wed Feb 16 14:00 2011 +0100" git commit --amend
GIT_COMMITTER_DATE="Mon 20 Aug 2018 20:19:19 BST" git commit --amend --no-edit --date "Mon 20 Aug 2018 20:19:19 BST"
Finish by typing the follow command
$ git rebase --continue
To create a tag on your current branch, run this:
git tag
$ git tag <tagname> -a
$ git push origin --tags
$ git push origin <tag>
$ git tag -d <tag>
$ git push origin :refs/tags/<tag>
merging-vs-rebasing Resetting, Checking Out & Reverting Advanced Git Log Merge Strategy