IT’S A GOOD IDEA TO FOLLOW THIS GUIDE BEFORE INSTALLING GITKRAKEN OR TORTOISEGIT!!!
So, you’ve downloaded Git from https://git-scm.com/download/win. Go ahead and install it. I recommend keeping it on your C drive. This is a straightforward process, all the defaults are fine. Just spam the ‘Next’ button and get it installed.
Right click anywhere on your desktop and open Git Bash:
Now you want to type a series of git commands:
- Type this using your email address tied to your GitLab account:
ssh-keygen -t rsa -C "email@example.com"
This command will prompt you for a location and filename to store the key pair and for a password. When prompted for the location and filename, just press enter to use the default. If you use a different name, the key will not be used automatically.
- Now one last command will copy this key for you so that you can paste it in to GitLab:
cat ~/.ssh/id_rsa.pub | clip
- Go to GitLab and under Profile Settings > SSH Keys, paste your key in, providing a name as well. The whole process looks like this:
That’s it. All set up. Now you can browse to your project on GitLab and clone your project to your machine by browsing to your folder of choice, right-clicking to open up GitBash, and running the following command:
replacing that last part with your project’s SSH address found on GitLab:
After that, you are free to commit, push, pull and change branches to your hearts content.
For more Git commands, see my other two posts on this topic:
Your usual day-to-day Git tasks will usually just involve getting the latest work from the remote, and otherwise pushing your local work to the remote. These tasks are written line-by-line in the Git Bash as follows:
- Clone a project from the remote for the first time:
git clone git@server:namespace/project.git
- Create a branch:
git checkout -b feature/branch_name
git push --set-upstream origin feature/branch_name
- Commit your work:
git add *
git commit -m "This is a commit message"
- Switch to a different, existing branch:
git checkout feature/branch_name
- Delete a branch
git branch -D feature/branch_name
git push origin :feature/branch_name
For a more complete guide on common Git tasks via the command line, see my guide: Common Git Commands.
In most cases, there is a GUI client application available for helping you work with GIT, otherwise, GIT is operated via shell commands in the command line. Here is a list of commonly useful GIT commands for use with GIT Bash.
git clone sshAddressToClone
- Clones the specified project in to the current directory.
- A non destructive way to update your local from the remote. Receive all changes without merging them to your current branch.
- Merge remote changes received by
git fetch to your local changes.
- A shortcut for fetching and merging in a single command. Recommended for efficiency where caution is not strictly needed.
- Send your committed changes from your current branch, to the server.
git push origin :branchName
- Deletes a branch on the remote.
git push origin :oldName newName
- Rename the specified branch on the remote.
- Check for the git status of all added, removed and otherwise changed files in your current branch.
git add path/to/your/file.fileType
- Take changed or added files, and stage them for commit.
* can be used in place of the file-path if you wish to add every file.
git rm path/to/your/file.fileType
- Remove or confirm the removal of files you’ve deleted locally. This needs to be done for your commit to acknowledge their removal.
* can be used in place of the file-path if you wish to remove every file.
- See what branches are present on your local machine. This is not a fair reflection of all available branches you can switch to. For that, see
git remote show origin.
git branch -d branchName
- Remove your branch locally, this does not remove it from the server, use a capital
D if you want to remove from the server, you can add
-f if you also want it to ignore the fact that you have changes to commit or clean from that branch before removing it.
git checkout filePath
- Reverts changes to whichever file is specified.
git checkout branchName
- Switch to any other existing branch, this includes branches that exist on the remote that you don’t currently have kept locally.
git checkout -b branchName
- Creates a new branch by the specified name and switches to that branch. You will need to run
git push --set-upstream origin branchName to place your new branch on the remote.
git push --set-upstream origin branchName
- Sets the current branch to the named location on the remote. This usually follows when you create a new branch via
git checkout -b branchName.
git remote show origin
- Shows the status of every branch found on the remote. It will also tell you which of your local branches have an upstream set.
git clean -fdx
- Removes any files that have changed or been added since your previous commit. It is often followed by
git reset --hard.
git reset --hard
- Often follows
git clean -fdx. Discards all changes in the working tree since the previous commit.