April 28, 2024

Git/BitBucket Cheatsheet

I use BitBucket for some low-key ASP.NET and Objective C source control needs. This is a cheatsheet of some of the things I do on an irregular basis.

New ASP.NET Project Startup

Usually about this time I’ll wonder if source control really is worth the hassle. Eventually I’ll decide (again) that it is.

After creating the project in .NET and getting something coded that’s worth saving, I’ll initialize the solution folder for use with Git:

In Windows Explorer, right-click on the solution’s folder and do a Git Bash Here (I’m using Git for Windows)

At the command prompt:  git init

This initialized the git repository but there’s nothing in there yet.  Veterans of Visual Studio and other IDEs will know that there are numerous project-related files that don’t belong in your source control system.  In Git, you can exclude them using a .gitignore file.  By Googling, I arrived at an exclusion strategy that works for me, so I’ll usually just copy a .gitignore file from a previous project into the newly-initialized repository.

Now it’s time to add files to the repository.  There’s probably an easier way, but I do it in 2 steps:

git add *.sln

git add ProjectFolder1

git add ProjectFolder2 (and so on…)

Now I can commit the files to the repository:

git commit -a -m “Initial check-in or other clever comment”

That’s good, but my real goal is to get a backup of the repository onto BitBucket.  Creating a repository there is easily done via their web site.  In fact, after this is done, BitBucket even gives you a mini-cheatsheet of how to push your local repository to the BitBucket remote.

With the Bash window still open:

$ cd /path/to/my/repo

$ git remote add origin https://youraccount@bitbucket.org/yourteam/yournewrepository.git

$ git push -u origin –all

Note that the BitBucket SSH configuration must be performed on a new development machine for this to work.

Also note that you’ll need your BitBucket account password to do the final push.

Updates to an ASP.NET Project

Updating a .NET project is pretty much the same as creating it.
New files are added with the git add command, then committed locally with git commit, as before.
Updates are then pushed to BitBucket using:

$ git push origin master

Leave a Reply