Run basic Git commands

Although some people prefer user interfaces, I prefer using the command-line to work with Git. In this article, I will review the simple sequence that I use most often.

First, I check out a branch. This might be the develop (integration) branch, or it might be a specific release.

git checkout <branch>

Next, I pull the latest code from the remote repository. This synchronizes the local files on my machine with the remote repository.

git pull

Then, I create my feature branch. I refer to this as a temporary container that keeps my work separate from everyone else’s until it is reviewed and approved.

git checkout -b feature/<feature name>

Next, I add, modify, or delete information. When I am done with my updates, I commit them to the working directory and then push the changes. However, I like to see the status along the way. After I have modified files, running the following command lists the file changes.

git status

Committing changes moves them from my working repository to my local repository.

git commit

We have a hook that opens a text editor like Notepad++ where I enter my commit message. After I close the editor, the commit finishes. I often run another status check.

git status

Now, it is time to push the content to the remote repository. Sometimes, the command needs more information. But, if I type the following, it returns the full Git push command that I can copy and paste.

git push

Now, I am done with my command-line work! Next, I open a web browser and create a Pull Request in the Bitbucket repository so that my work is approved and merged into the develop branch.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s