MOVE37 About Blog Project Links

Version Control 101

Case 1: We want to create a new repo

Yea go for it. Use git init to initialize your git repo. After you have the new repo created, basic operations that will come in handy are:

Before you actually make the commit, you want to use git diff to see the file changes.

How to make local commit?

First, use git add . to add all the files that changed or git add [file name] to include only the files you want.
Then, we commit the code with the a summary by entering git commit -m "YOUR MESSAGE". If there is a lot of changes and you want to describe them in details, you use git commit to enters VIM mode.

Then, if you want to push the code to the remote repo, you use git push origin [branch-name]. If you want to pull from remote you use git pull origin [branch-name]. Note that you want to pull often, especially if you are using Jenkins for automated build since the build numbers and stuff. My mentor Rahul told me that every morning is a fresh start and we should pull from github.

For branch related operations, we check all the local branches by entering git branch and checkout the branch you want with git checkout [branch-name]. We create new branch with git checkout -b "BRANCH NAME". We delete local branch with git branch -d [branch-name] and delete remote branch with git push origin --delete [branch-name].

Case 2: We want to trash the current changes and pull from remote

You use git rebase -- . to revert your repo to the last commit.

Case 3: I just downloaded someone else’s repo. I want to change the remote repo to my own.

You use git remote -v to view current remotes. You use git remote rm [origin] to remove remote and git remote add origin [url] to add a remote.

Case 4: TBC.

I still need to learn how to use git reset. Man git is so powerful.


Share this: