GitHints
Hints for daily faced challenges in git.
day 0: Clone branch from remote repository
will clone only master branche
git clone https://github.com/RooBarsic/GitHints.git
will clone branch with name "branch_name"
git clone --branch branch_name https://github.com/RooBarsic/GitHints.git -
day 1: Create new branch
- check branches that you already have
git branch
- Move to the base branch from which you want to create new branch ( usually it's master branch )
git checkout BranchName
- create new branch
git branch NewBranchName
- remove branch if you made mistake in branch name, or you come up with better idea of branch name
git branch -D NewBranchName
- check is there your NewBranchName in branches that you already have
git branch
- Move to the created branch
git checkout NewBranchName
day 2: Make commit and push changes to remote repository
- check the changes
git status
- add files to index in order to make commit
git add . - will add all changed files to index
git add PathToFile - will add exactly file to index
git reset PathToFile - will remove exactly file from index
- make sure that all necessary files are added
git status
- make loacal commit with message
git commit -m "commit_message" - will make commit with given message
- push commit to the remote repository
git push origin HEAD
day 3: Chage message of last pushed commit
git commit --amend -m "NewCommitMessage"
git push --force origin HEAD
day 4: Remove some files from last pushed commit
- move back HEAD to previous commit
git reset --soft HEAD~1
- check the changes
git status
- remove useless files from this commit
git reset PathToFile
- push changes to remote repository
git push --force origin HEAD