Below are some basic commands for working with GIT repositories using the command line client. They are useful if you’re just starting out with Git, or if you keep forgetting the exact parameters.
Clone a repository
git clone <git-repo-url>
Repository status (working copy status)
Commit a change
git commit -m "Message"
Note: Make sure you have added the files to the index first:
git add -a .
Push chnages to the remote repository
git push origin master
Pull changes from the remote repository
git pull --rebase origin master
Note: Be sure to replace
master with the branch that you want to update.
Switch to a different remote repository
git remote remove origin git remote add origin <new-origin-url>
View the log (simple case)
View the log in pretty format
git log --graph --oneline --all --decorate
View changes in a commit
git diff-tree --no-commit-id --name-only -r bd61ad98
git checkout -- <name-of-file>
Note: The above command brings the specified file to the current index state (if any). To completely revert all changes, you will need to either run
git reset <name-of-file> git clean -f
You can also reset the entire tree to the last commit
git reset --hard
Create a branch
git checkout -b feature1 git push -u origin feature1
git branch -a
Merge changes from a branch
git merge --no-ff <branchname>
Delete a branch
git branch origin :<branch-name> # deletes the branch from the remote git branch -d <branch-name> # deletes the local branch