Just to revise my Git concepts, I enrolled myself in an online course on Udacity. The name of the course is “How to Use Git and GitHub”. It is a wonderful course which gives you quite a good overview of both Git and GitHub. It was recommended to me by one of my students. While going through the course I made some short notes. After the completion of the course, I realized that these notes could work as a good quick guide to Git commands.
Here are the commands:
- Downloading repo: git clone urlOfGitHubRepository
- To check all previous commits: git log
- Checking differences between commits: git diff commitID1 commitid2
- To get colors as diff output: git config –global color.ui auto
- Moving back to some previous commits: git checkout commitID
- Creating a new repository: git init
- Checking the status of the git repository: git status
- Working directory -> Staging area -> Repository : git add filename
- Git committing with a message: git commit
- Checking changes from working directory to staging area: git diff
- Checking changes from staged area to the directory: git diff –staged
- Disregarding the changes in the working directory and staging are: git reset –hard
- To see the branches in your project: git branch
- Creating a new branch: git branch branchname
- To see the updated change in the branch, check out the branch: git checkout easy-mode
- To see the branch structure: git log –graph branchname
- To see the graphs simpler: git log –graph –oneline branchname
- To create a merged version of two branches: git merge branchname1 branchname2
- To see the changes between a commit and its parent: git show commitID
- After the merge you might not need the merged branch, so to delete it: git branch -d branchname2
- Git represents the merge conflict using some symbols like: >>>> ||||| =====
- To see only a commit: git log -n 1
GITHUB
- While making a new repo if you haven’t made any previous commits then check: Initialize this repository with a README
- To create a remote: git remote
- To add the repository on GitHub as a remote: git remote add anyRemoteName urlForTheRemote
- To get more data about the git remote: git remote -v
- To push your repo content to GitHub: git push RemoteName branchName
- To pull the content from the GitHub: git pull RemoteName branchName
- In case of an update on both local machine and GitHub, we can run: git fetch remoteName