Most git commands should be executed at the base directory of a repo, I.e. where the .git folder is.
git config --global user.name "Arhtur Dent"
git config --global user.email "arhur.dent@thgttg.somesillydomain.com"
git clone https://gitlab.com/arthur.dent/TestRepo.git
cd TestRepo
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
cd existing_folder
git init
git remote add origin https://gitlab.com/arthur.dent/TestRepo.git
git add .
git commit -m "Initial commit"
git push -u origin master
cd existing_repo
git remote add origin https://gitlab.com/arthur.dent/TestRepo.git
git push -u origin --all
git push -u origin --tags
git add .
git commit -m "some clever comment"
git push -u origin master
git pull origin
git add .
git commit -m "some clever comment"
git checkout -- filename
git checkout .
...and move back into staging.
git reset --soft HEAD^
git branch -a
git checkout -b myBranch
-- same as –
git branch myBranch # creates a branch
git checkout myBranch # switches to it
Make sure you don’t have any uncommited changes, and then do:
git checkout myBranch
git remote -v
Preferred over merging. This will make changes to your target branch only.
First make sure that your master is up to date:
git checkout master
git pull origin
Then make sure that your target branch is ready for rebasing:
git checkout targetBranch
Now there are two options
Option 1:
<add/commit all changes>
Option 2:
git stash
Then, on the target branch, perform the rebase:
git rebase master
If you opted for Option2
git stash pop
Switch to the target branch:
git checkout master
Then do the merge:
git merge myBranch
git branch -d myBranch
While in other branch:
git branch -m oldname newname
Rename the current branch:
git branch -m newname
git clone https://github.com/arthur.dent/myfork.git
git remote add upstream git://github.com/sourceuser/sourceoffork.git
git fetch upstream
git rebase upstream/master
git stash
git stash
git stash branch myNewBranch
git checkout --theirs myFile
or
git checkout --ours myFile
or edit file in editor then
git add myFile
or
git rm myFile
git merge --abort
Two ways of doing this
Use
git rebase -i <after-this-commit>
and replace "pick" on the second and subsequent commits with "squash" or "fixup", as described in the manual.
In this example, is either the SHA1 hash or the relative location from the HEAD of the current branch from which commits are analyzed for the rebase command. For example, if the user wishes to view 5 commits from the current HEAD in the past the command is
git rebase -i HEAD~5.
Credit StackOverflow
Second way of doing this
You can do this fairly easily without git rebase or git merge --squash. In this example, we'll squash the last 3 commits.
If you want to write the new commit message from scratch, this suffices:
git reset --soft HEAD~3 &&
git commit
If you want to start editing the new commit message with a concatenation of the existing commit messages (i.e. similar to what a pick/squash/squash/…/squash git rebase -i instruction list would start you with), then you need to extract those messages and pass them to git commit:
git reset --soft HEAD~3 &&
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"
Both of those methods squash the last three commits into a single new commit in the same way. The soft reset just re-points HEAD to the last commit that you do not want to squash. Neither the index nor the working tree are touched by the soft reset, leaving the index in the desired state for your new commit (i.e. it already has all the changes from the commits that you are about to “throw away”). Credit StackOverflow
This command deletes remote tracking branches that don't exist anymore on the remote. To see which branches would be deleted:
git remote prune --dry-run origin
To actually prune the branches:
git remote prune origin
git tag
git tag -a v1.4 -m "my version 1.4" # Annotated tag
git tag v1.4-lw # Lightweight tag
git checkout v1.4 # For viewing
git checkout -b v1.4.1 # ...branch v1.4 tagged source into new branch v1.4.1
Or, all in one command:
git checkout -b v1.4.1 v1.4 # check out source with tag v1.4 and create new branch v1.4.1
git log -- <filename>
git cat-file -p <sha1>:./file.tex > wherever.tex