A list of the most commonly used git commands
Navigate into the folder you want to clone your project into
$ cd /chosen-path/
Then clone it
$ git clone [project URL]
If you want to do a shallow clone which would only get the recent commit and ignore all of the repos history you can do
$ git clone [project URL] --depth=1
Which files have changed, which branch is git using, etc
$ git status
$ git add [file or directory]
$ git commit -m 'your commit message'
$ git push
$ git checkout -b [branch-name]
$ git push -u origin [branch-name]
$ git checkout [branch-name]
$ git branch
Make sure you're not on the branch you want to delete otherwise it will not work
Delete a remote branch
$ git push origin --delete [branch-name]
Delete a local branch
$ git branch -d [branch-name]
$ git checkout -b [branch-name] origin/[branch-name]
Go onto the branch you want merge into, for example 'develop' then merge in your choosen branch for example 'kim-footer-amend'
$ git merge [branch-name] --no-commit --no-ff
(the --no-commit does not automatically commit the branch after merging and --no-ff does not fast forward the branch you're merging into)
This will check out their file if you know yours is incorrect
$ git checkout --theirs /path-to/conflict-file
This will check out your file if you know the one in the repo is outdated
$ git checkout --ours /path-to/conflict-file
Otherwise, you'll have to manually sort through them in the conflicted file. Make sure you have no <<<
or >>>
in your file as your conflicts live in these.
This will undo all of your changes for a single file. This will lose any amends you haven't committed so only do this if you're sure.
$ git checkout -- /path-to/file
If you want to delete your current changes and revert back to the previous commmit (this will lose any amends you haven’t committed so only do this if you're sure)
$ git reset --hard
$ git log